I have a string representation of an array:
'["item1", "item2", "item3"]'
I'm trying to convert this back to an array.
Any pointers appreciated.
Just use JSON.parse('["item1", "item2", "item3"]');
Try JSON.parse:
ary = JSON.parse(s);
Most browsers support it natively, for others you'll need json.js
eval
for this task and it will accept single quotes, but make sure you think it through first - Jesse 2012-04-04 01:22
You also can Use
var genericList = eval('(' + s + ')');
for(i=0;i<genericList.lengthl;i++){
alert("element : " + genericList[i]);
}