I'm beginner in javascript and I have a problem to convert a string to a array of int. I find for this case
var string = "[1,2,3,4]";
but not for this one:
var string = "[[1,2],[1,2]]";
And have the same syntax
var result = [[1,2],[1,2]];
result = [[1,2],[1,2]];
JSON.parseshould handle both. Perhaps the question could be clearer. What is your expected output forvar string = "[1,2,3,4]";JSON.parsewill convert that to the expected output.eval("[[1,2],[1,2]]")evalunless you have to dynamically write actual javascript code. Using it to parse JSON data is unsafe and highly discouraged.