maztt maztt - 5 months ago 48
Javascript Question

JavaScript array of arrays

i have a JavaScript array of string arrays: array1; array2 ; array3 which i need to break and then access the individual array. how can i do that?


You can use the split method:

var str = 'array1; array2 ; array3';
var arr = str.split('; ');

To access the individual array parts, you need to use index which starts from 0:

alert(arr[0]); // shows first item
alert(arr[1]); // shows second item
alert(arr[2]); // shows third item

Or you can loop through the array like this too:

for(var i = 0; i < arr.length; i++)