Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

slice

The slice() method of the Array object returns an array that is a portion of an original array by specifying the start/end indexes of the slice. The original array is unaffected. If the 'end' parameter is not defined the slice will go all the way to the end of the array.

Syntaxarray.slice( start, end )

Parameters

start Specify the index position in the array to start the slice from. end (optional ) Specify the index position to slice up to, but not including the end index.

Examples

Slice a ranged portion: var arr = ["a","b","c","d","e","f"]; /* starting from index 2, slice up to but not including index 4 */ var portion = arr.slice( 2, 4 ); alert( portion ); /* c,d */ Slice from the start index to the end of the array by omitting the second parameter: var arr = ["a","b","c","d","e","f"]; /* starting from index 2, slice the rest of the array elements */ var portion = arr.slice( 2 ); alert( portion ); /* c,d,e,f */

JavaScript

Methods

addEventListeneralertaveragebackblurconcatcreatedecodeURIdecodeURIComponentencodeURIencodeURIComponentevaleveryfilterforwardgoisArrayisFiniteisNaNjoinparseFloatparseIntpoppushpushStatereducereplaceStatereverseshiftshuffleslicesomesortspliceunshiftwrite