David Luque
David Luque

Reputation: 1108

Append to an array in an API node.js

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

Answers (1)

user663031
user663031

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

Related Questions