Is it possible to turn this:
var a = "[0,0,1,1,0,0,1,[1,0,2]]";
into an array so it will work with this?
var newArray = a; // now newArray is [0,0,1,1,0,0,1,[1,0,2]], not "[0,0,1,1,0,0,1,[1,0,2]]"
Is it possible to turn this:
var a = "[0,0,1,1,0,0,1,[1,0,2]]";
into an array so it will work with this?
var newArray = a; // now newArray is [0,0,1,1,0,0,1,[1,0,2]], not "[0,0,1,1,0,0,1,[1,0,2]]"
var a = "[0,0,1,1,0,0,1,[1,0,2]]";
var result = JSON.parse( a );
In addition to JSON.parse
you could use eval
:
var a = "[0,0,1,1,0,0,1,[1,0,2]]";
var newArray = eval(a);
As for a discussion on whether to use JSON.parse
or eval
, see this SO discussion: JSON.parse vs. eval()
Yes, it is possible, these browsers support JSON.parse(), which will parse a given String and converts it into an object, if the given string is a valid JSON representation.
Also you can do:
var result = eval("[0,0,1,1,0,0,1,[1,0,2]]");
You result will be:
[0, 0, 1, 1, 0, 0, 1, Array[3]]