1. Arrayobject.slice (start,end) returns the selected element from an existing array
| 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 an empty parameter is used, the copy function of the array can be implemented
var ori = [' Bank ', ' hello ', ' Hey ', ' man '];//take [to] left open right closed Console.log (Ori.slice ()); ["Hello"]//negative number 1,-1 from the start to 1,end for arr.length-1//i.e. [1,arr.length-1]console.log (Ori.slice (1,-1));//["Hello", " Hey "]
Array replication
var ori = [' Bank ', ' hello ', ' Hey ', ' man '];//array copy var res = Ori.slice (); Console.log (ori);//[' Bank ', ' hello ', ' Hey ', ' man '];
JavaScript Common method collation--array