0

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?

1
  • can you show some code so that we can understand well what are you trying to work on... it quite confusing... Commented Aug 24, 2010 at 3:17

1 Answer 1

3

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]);
}
Sign up to request clarification or add additional context in comments.

2 Comments

i think it's better if you split it with just ";", then just trim it.. so leading and trailing spaces will be omitted...
how can i access the elements in the array

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.