I am trying to turn a string like:
"[["firstVal","secondVal"],["firstVal","secondVal"]]"
Into a javascript array (It is a 2D array)
Is there a way that I can do this using javascript or jQuery?
Many Thanks!
I am trying to turn a string like:
"[["firstVal","secondVal"],["firstVal","secondVal"]]"
Into a javascript array (It is a 2D array)
Is there a way that I can do this using javascript or jQuery?
Many Thanks!
You can use JSON.parse to achieve what you require:
var str = '[["firstVal","secondVal"],["firstVal","secondVal"]]';
var arr = JSON.parse(str);
console.log(arr);
Note that I had to amend the outer quotes to ' as your example string is malformed.
Use JSON.parse() method to do that :
JSON.parse('[["firstVal","secondVal"],["firstVal","secondVal"]]');