I have a string like "[1,2,3]" and I want to convert it into array like [1,2,3] using JavaScript. Can anyone help me to do this?
2 Answers
Since the string you want to convert is compatible to the JSON format (JavaScript object notation), you can use JSON.parse to convert it into an array:
const str = "[1,2,3]";
const arr = JSON.parse(str);
console.log(arr);
1 Comment
Patrick Hund
Always glad to help!
Here you go
var dat = "[1,2,3]";
var myData = JSON.parse(dat);
console.log(myData);
1 Comment
Bahroze Ali
Nvm just saw the above answer.
<br>? I don't see you are hidding themJSON.parse()