Javascript/Jquery Convert string to array

The Solution to Javascript/Jquery Convert string to array is


Since array literal notation is still valid JSON, you can use JSON.parse() to convert that string into an array, and from there, use it's values.

var test = "[1,2]";
parsedTest = JSON.parse(test); //an array [1,2]

//access like and array
console.log(parsedTest[0]); //1
console.log(parsedTest[1]); //2

~ Answered on 2012-08-02 11:12:23


Most Viewed Questions: