I have a String like
var str = "['one','two']"
i want to convert it into a array, what are the possibilities ?
is there a elegant solution than stripping quotes
I have a String like
var str = "['one','two']"
i want to convert it into a array, what are the possibilities ?
is there a elegant solution than stripping quotes
You can use the replace()
and split()
methods:
var str = "['one','two']";
str = str.replace( /[\[\]']+/g, '' );
var strarr = str.split( ',' );
console.log( strarr )