Topic: How to access a range within a mulidimensional array |
|
---|---|
Author | Thread |
Nervous Wreck (II) Inmate From: |
posted 12-07-2009 21:23
My javascript array has values for "chapter", "paragraph", |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 12-08-2009 11:03
Do you only want to do this to calculate word counts? Or do you want to get a new array so you can do other things with it? I'll assume the latter, since it's more generally useful. code: firstChapter = 4; lastChapter = 6; line = 0; // skip the lines we don't want for ( ; line < book.length; line++ ) { if ( book[line][0] == firstChapter ) break; } // grab the lines we do want result = new Array(); for ( ; line < book.length; line++ ) { if ( book[line][0] > lastChapter ) break; // stop when we see something we don't want result[result.length] = book[line]; // append this line to the end of the 'result' array // if all you want is word counts, you could just tally the word count here instead. } return result;
|
Nervous Wreck (II) Inmate From: |
posted 12-08-2009 18:07
Thanks Slime; |
Nervous Wreck (II) Inmate From: |
posted 05-31-2011 11:03
Edit TP: spam removed
|