1

I am trying to pass the array with the help of query string but when i am fetching it using nodejs it act as a string.

my query string is like -

'/home?page='+value;

  where value is [{name : 'a'},{name :'b'},{name : 'c'}]

but the problem is when i send it in node js and apply

console.log(req.query.page[0].name) output is [object object] but i want the output a

Please help me in this problem

Rupesh
  • 850
  • 2
  • 13
  • 30

1 Answers1

1

I think the problem might be that you are sending a raw object as a parameter. Try doing '/home?page=' + JSON.stringify(value) and console.log(JSON.parse(req.query.page[0].name)).

You may also need to encode the param like so: ecodeURI(JSON.stringify(value)) and decode with decodeURI, like so: decodeURI(req.query.page[0].name)

Levi V
  • 78
  • 1
  • 7