I use stringify on my node restful server to provide data:
answer = JSON.stringify({activities: result}, null, '\t'); return answer
where result is the js object; I get the correct output for this:
{ "activities": [ { "id": 1, "title": aaa }, { "id": 2, "title": bbb } ] }
but now I would like to use a variable instead of a fixed string on the left side of the stringify function; sort of:
var name = "activities"; answer = JSON.stringify({name: result}, null, '\t');
this does not work because the name becomes a fixed string in a string object
source share