2

I have a trouble with NodeJS. I have to send an array of array that is structured like this:

[
   "val1":["one","two","three"],
   "val2":["four","five","six"],
   "val3":["seven","eight","nine"]
]

So, when I try to do res.send, in my browser (Chrome) I show only [].

How can I send my array?

1
  • 3
    That's not a valid JavaScript structure. You can't JSON-encode it as it throws a syntax error. Commented Oct 19, 2016 at 14:18

1 Answer 1

3

The send function expects a JavaScript object, which can be marshalled as a valid JSON string. In your case, you have a JavaScript array, with three properties. But JSON arrays support only integer keys (called indices).

So, you might want to change the array to a JavaScript object, like this

res.send({
  "val1": ["one", "two", "three"],
  "val2": ["four", "five", "six"],
  "val3": ["seven", "eight", "nine"]
});
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.