㈠slice () method
⑴ can be used to extract elements from the specified array
This method does not change the elements of the array , but the package will be taken to the element to return a new array
⑵ syntax:
arrayObject.slice(start,end)
⑶ parameters:
1. taken start index position, comprising a start index
2. intercepted end indexed position, does not contain the ending index
- The second parameter can be omitted , then the elements will intercept all subsequent index from the start
⑷ index may pass a negative value , a negative value if passed, calculated from back to front
-1: a penultimate
-2: penultimate
⑸ Example 1: intercepting Index
⑹ Example 2: The second parameter can be omitted
⑺ Example 3: transmitting a negative index
㈡splice () method
⑴ can be used to delete the specified elements in the array
⑵ use splice () will affect the original array , will specify the elements that were removed from the original array
And will be removed elements returned as the return value
⑶ parameters:
The first represents the index start position
The second represents the number of deleted
The third and beyond. . .
You can pass some new elements that will be automatically inserted into the starting position in front of the index
⑷splice( ) 方法是一个多功能的方法:可以删除元素,可以替换元素,可以在数组的指定位置插入(添加)元素
⑸示例1:删除元素
⑹示例2:参数所表达的意义
⑺示例3:替换元素,指定位置插入元素