Javascript array to JSON - using var


#1

Hey guys,

I have a JavaScript array, which I want to convert to JSON.
The thing is that I don’t know what will be in the array, cause it’s a calculator, that depends on the user.

I saw some commands that parse js to json, but the thing is that I want to be able to use a VARIABLE instead of a fixed input.

Let’s take this as an example:

var obj = { "name":"John", "age":30, "city":"New York"};
var myJSON = JSON.stringify(obj);

I want to be able instead of “John”, or “30”, or “New York”, to be able to use a var. let’s say array[4].name or anything, cause I don’t know those values.


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.