JS Array Splice method
function
The splice () method adds/deletes an item to/from the array, and then returns the item that was deleted.
1. Add
Let arr = [n/a];
Console.log (arr); //[1, 2, 3]
Array.prototype.splice.call (arr,1,0, ' 4 ');
Console.log (arr); //[1, "4", 2, 3]
/**
* Array.prototype.splice.call (arr,1,0, ' 4 ');
* Call after Arr is an array that points to arr,1 is the position of the ARR array where the 1 (second) element is inserted into an element, 0 means not removing other elements, ' 4 ' is the inserted element;
* /
2. Modifications
Let arr = [n/a];
Console.log (arr);//[1, 2, 3]
Array.prototype.splice.call (arr,1,1, ' 4 ');
Console.log (arr);//[1, "4", 3]
/**
* Array.prototype.splice.call (arr,1,1, ' 4 ');
* The arr behind the call is the array that points to arr, the first 1 is the position of the 1 (second) element in the ARR array, and the second 1 is the element that is inserted at the position of the subscript 1, and the ' 4 ' is the elements being injected;
*/
3. Delete
Let arr = [n/a];
Console.log (arr);//[1, 2, 3]
Array.prototype.splice.call (arr,1,1);
Console.log (arr);//[1, 3]
/**
* Array.prototype.splice.call (arr,1,1);
* The arr behind the call is an array to arr, the first 1 is the position of the 1 (second) element in the ARR array, and the second 1 is the deletion of an element at the position of the subscript 1;
*/
Array Splice method