Short question. How can I convert a string to the JS array?
Look at the code:
var string = "0,1";
var array = [string];
alert(array[0]);
In this case, alert
would popup a 0,1
. When it would be an array, it would popup a 0
, and when alert(array[1]);
is called, it should popup the 1
.
Is there any chance to convert such string into a JS array?
string[0] === '0'
in your question), in most cases you can treat a string as an array of chars and use array methods on it. – Paul S. Nov 7 '12 at 15:19