Pick Grass from W3
The slice () method returns the selected element from an existing array.
Grammar
Arrayobject.slice (Start,end)
Parameters |
Description |
Start |
Necessary. Specify where to start the selection . If it is a negative number, it specifies the position from the end of the array . In other words, 1 refers to the last element, 2 refers to the second-lowest element, and so on. |
End |
Optional. Specifies where to end the selection. The parameter is the array subscript at the end of the array fragment. If this parameter is not specified, then the segmented array contains all elements from start to end of the array. If this parameter is a negative number, it specifies the element starting from the end of the array. |
return value
Returns a new array containing elements from start to end (excluding the element) from the Arrayobject.
Description
Note that the method does not modify the array, but instead returns a subarray. If you want to delete an element from an array, you should use Method Array.splice ().
Hints and Notes
Note: You can use negative values to select elements from the end of an array.
Note: If end is not specified, then the slice () method selects all elements from start to the end of the array.
JS removes the beginning of the string or the first few characters. Slice can also be used to intercept a part