Reputation: 1108
I need to append an item to an API in Node.js.
This is my code
app.post('/api/scores', function(req, res){
//creamos el score para guardarlo en la bd
Score.create({
userEmail : req.user.email,
game : game,
top : top.push(10)
})
})
Can I do this top.push()?
Upvotes: 0
Views: 87
Reputation:
Sure, if you want to pass the return value of push
, which is the new length of the array. See the docs.
You probably want
top: top.concat(10)
because concat
returns the new array, which is most likely what you want.
Upvotes: 4