Share via


slice Method (Array) (JScript 5.6) 

Returns a section of an array.


arrayObj.slice(start, [end]) 

Arguments

  • arrayObj
    Required. An Array object.
  • start
    Required. The index to the beginning of the specified portion of arrayObj.
  • end
    Optional. The index to the end of the specified portion of arrayObj.

Remarks

The slice method returns an Array object containing the specified portion of arrayObj.

The slice method copies up to, but not including, the element indicated by end. If start is negative, it is treated as length + start where length is the length of the array. If end is negative, it is treated as length + end where length is the length of the array. If end is omitted, extraction continues to the end of arrayObj. If end occurs before start, no elements are copied to the new array.

Example

In the following example, all but the last element of myArray is copied into newArray:

newArray = myArray.slice(0, -1)

Requirements

Version 3

Applies To: Array Object (JScript 5.6)

See Also

Reference

slice Method (String) (JScript 5.6)
String Object (JScript 5.6)