0

I'm trying to send array using ajax, imagine the array

var anotherOne = 'anotherOneData';
var documents = ['banana', 'apple', 'monkey'];

I sent these normal value and array to server-side, using ajax, no problem with got this in server side,

console.log(req.body);

//result (anotherOne is I sent too, this is not array,)
{ anotherOne : 'anotherOneData',
  'documents[]': 
[ 'banana', 
'apple, 
'monkey' ] }

How can I access documents's first element?

req.body.documents[0] // not working
req.body.documents[0][0] // not working
req.body.documents instanceof Array // false : why?

I'm totally couldn't get what's going on, Please help me.

1
  • Could you post the code you're using to submit the AJAX call? Commented Feb 18, 2016 at 6:39

1 Answer 1

1

Based on what you've logged, the property on req.body is called documents[], so:

console.log(req.body['documents[]'][0]);

That said, I think I'd send it as JSON and then parse it on the server.

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.