Javascript array to JSON

Javascript array to JSON

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:

  1. var obj = { "name":"John", "age":30, "city":"New York"};
  2. 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.