0

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()?

0

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.