Returns a section of an array.
arrayObj.slice(start, [end])
Parameters
Arrayobj
Required option. An Array object.
Start
Required option. The starting element of the part specified in arrayobj is the zero-based subscript.
End
Options available. The end element of the part specified in arrayobj is the zero-based subscript.
Description
The slice method returns an Array object that contains the specified portion of the arrayobj .
The slice method is copied to the element specified by end, but does not include the element. If start is negative, it is the length + start processing, where length is the size 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, the slice method is copied to the ending of arrayobj . If end appears before start , no elements are copied into the new array.
Example
In the following example, all elements in themyarray are copied to the NewArray except for the last element:
newArray = myArray.slice(0, -1)