I have an array that has a bunch of content separated by colons, so for example initArray[0] might have the content 10:30:20:10. How do I split this again so I can have initArray[0][1]. Any help is appreciated!
-
I tried a bunch of things but I couldn't get it to work at all. Javascript is not my forte.Johnny– Johnny2012-03-14 14:31:44 +00:00Commented Mar 14, 2012 at 14:31
Add a comment
|
3 Answers
If you want to split every element in the array:
for( var i = 0; i < initArray.length; i++ ) {
initArray[i] = initArray[i].split( ':' );
}
So this:
[ '10:30:20:10', 'a:b:c:d' ]
becomes:
[ [ '10', '30', '20', '10' ], [ 'a', 'b', 'c', 'd' ] ]
1 Comment
Johnny
oh god, I realised what I was doing wrong, I had the i and initArray.length the wrong way around in my for loop. I thought my syntax was flawed.