AvailabilityJavaScript 1.2; JScript 3.0; ECMAScript v3 Synopsisarray.slice(start, end) Arguments
ReturnsA new array that contains the elements of array from the element specified by start, up to, but not including, the element specified by end. Descriptionslice( ) returns a slice, or subarray, of array. The returned array contains the element specified by start and all subsequent elements up to, but not including, the element specified by end. If end is not specified, the returned array contains all elements from the start to the end of array. Note that slice( ) does not modify the array. If you want to actually remove a slice of an array, use Array.splice( ). Examplevar a = [1,2,3,4,5]; a.slice(0,3); // Returns [1,2,3] a.slice(3); // Returns [4,5] a.slice(1,-1); // Returns [2,3,4] a.slice(-3,-2); // Returns [3]; buggy in IE 4: returns [1,2,3] Bugsstart cannot be a negative number in Internet Explorer 4. See Also |