
October 14th, 2008, 07:55 AM
| | | Re: Split Array
On 2008-10-14 03:06, dhtml wrote: Quote:
Evertjan. wrote: Quote:
>var oldArray = [4,5,6,1,2,3,4,8,5,9];
>var newArray = oldArray.slice(5,10);
>newArray = newArray.concat(oldArray.slice(0,5))
| | .... Quote: Quote:
>var oldArray = [4,5,6,1,2,3,4,8,5,9];
>var newArray = [];
>newArray = newArray.concat(oldArray.slice(5,10),oldArray.slic e(0,5))
| | .... Quote:
var items = [4,5,6,1,2,3,4,8,5,9];
var newArray = items.slice(5,10).concat(items.slice(0,5));
| .... Quote:
var items = [4,5,6,1,2,3,4,8,5,9];
var start = items.slice(5);
start.push.apply(start, items.slice(0,5));
| JFTR, all of these would require an additional loop to find the index of
the element with the value 3. "There's more than one way to do it"...
looks like we'll have a Javascript Golf Apocalypse soon ;-) http://en.wikipedia.org/wiki/Perl_Golf_Apocalypse
- Conrad | 
October 15th, 2008, 12:15 AM
| | | Re: Split Array
On Oct 14, 4:52*pm, Conrad Lender <crlen...@yahoo.comwrote:
[...] Quote:
JFTR, all of these would require an additional loop to find the index of
the element with the value 3.
| If that was a requirement, yes. *But* the OP didn't say how the index
used to split the array was chosen, only that for the example it was
from the element with value 3 (i.e. index 5).
--
Rob |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | |