OZONE Asylum
Forums
DHTML/Javascript
How to access a range within a mulidimensional array
This page's ID:
31520
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
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. Assuming the 'book' array is in order, you just need to write a loop that finds the first element you want, and then a loop that copies everything into a new array until you find the first element you don't want. [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; [/code] [url=http://www.slimeland.com/] [img]http://www.slimeland.com/misc/ozonemetalslimesig.gif[/img] [/url] [small](Edited by [url=http://www.ozoneasylum.com/user/5]Slime[/url] on 12-08-2009 11:03)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »