views:

40

answers:

1

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?

+3  A: 

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++)
{
  alert(arr[i]);
}
Sarfraz
i think it's better if you split it with just ";", then just trim it.. so leading and trailing spaces will be omitted...
Manie
how can i access the elements in the array
mazhar kaunain baig
@mazhar kaunain baig: See my updated answer please.
Sarfraz