3

I have a array: passedWord = ['a', 'bbb'] Then I use ajax request to send this array to nodejs server. On server, by Body Parser I receive:

{ name: 'abc', score: '27', 'passedWord[]': [ 'a', 'bbb' ] }

My code:

app.post('/add-score', function (req, res){
  console.log(req.body.passedWord) -->log: undefined
})

how do I read my array on nodejs server

1 Answer 1

2

Use bracket notation, which accepts string as the property name

app.post('/add-score', function (req, res){
   console.log(req.body["passedWord[]"]); // now it works
})

What cannot be written as such, due to variable naming rules, in dot notation, can be accessed using bracket notation.

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

1 Comment

@Mr.Dung glad it helped. Do mark it as answer by clicking the tick mark

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.