From http://www.w3schools.com (Copyright Refsnes Data)
JavaScript Array Object
The slice() method returns selected elements from an existing array.
| arrayObject.slice(start,end) |
| Parameter | Description |
|---|---|
| start | Required. Specify where to start the selection. Must be a number. Starts at 0 |
| end | Optional. Specify where to end the selection. Must be a number |
Tip: You can use negative numbers to select from the end of the array.
Note: If end is not specified, slice() selects all elements from the specified start position and to the end of the array.
ExampleIn this example we will create an array, and then display selected elements from it:
The output of the code above will be:
Try it yourself » |
JavaScript Array Object
From http://www.w3schools.com (Copyright Refsnes Data)