Node.js is there a way to send an array within a JSON response? -


i trying figure out if there way send array in json response in node.js have attached datapoints1, datapoints2 , datapoints3 within response arrays. when received ajax request, becomes string [object object],[object object]

responsearray = '{"result":{"system":"ready","allcompleted":"completed","datapoints1":"'+datapoints1+'","datapoints2":"'+datapoints2+'","datapoints3":"'+datapoints3+'"}}'; res.setheader('content-type', 'application/json'); res.type('application/json');     res.send(responsearray); 

is there way can send array within json string ajax call turn array? thanks

.send method accepts javascript object argument. don't need build string.

try with:

var responsearray = {   result: {     system: "ready",     allcompleted: "completed",     datapoints1: datapoints1,     datapoints2: datapoints2,     datapoints3: datapoints3   } };  /// ...  res.send(responsearray); 

ref.: http://expressjs.com/en/api.html#res.send


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -