slice array from N to last element
Solution 1:
Don't use the second argument:
Array.slice(2);
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/slice
If end is omitted, slice extracts to the end of the sequence.
Solution 2:
An important consideration relating to the answer by @insomniac is that splice
and slice
are two completely different functions, with the main difference being:
-
splice
manipulates the original array. -
slice
returns a sub-set of the original array, with the original array remaining untouched.
See: http://ariya.ofilabs.com/2014/02/javascript-array-slice-vs-splice.html for more information.
Solution 3:
Just give the starting index as you want rest of the data from the array..
["a","b","c","d","e"].splice(2) => ["c", "d", "e"]
Solution 4:
["a","b","c","d","e"].slice(-3) => ["c","d","e"]