First, splice grammar
Arrayobject.splice (start, deletecount,item1,....., ItemX)
1. Parameter description
start: Required. Specifies where to add/remove elements from. This parameter is the subscript that begins inserting and/or deleting an array element, which must be a number.
deletecount: Required. Specifies how many elements should be deleted. Must be a number, but it can be "0". If this parameter is not specified, all elements from index start to the end of the original array are deleted.
item1: Optional. Specifies the new element to be added to the array. Start the insertion from the subscript at index point.
ItemX : Optional. You can add several elements to an array.
2. Attention
1, the argument is negative, if start is negative, the length of the array is added as the value of start , and DeleteCount is negative or 0 will not perform the delete operation.
2. Using splice to delete the values in the array will directly remove a few items from the array, causing the array to change the length value, which is not the same as deleting the delete to undefined.
3 . The Splice method modifies the arrayobjby removing the specified number of elements from the start position and inserting the new element. The return value is a new Array object that consists of the elements that were removed.
Ii. Examples of Splice
var lang = ["PHP", "Java", "JavaScript"]; Remove var removed = Lang.splice (n); alert (lang); Php,javascript alert (removed); Java, return Deleted items//insert var insert = Lang.splice (0,0, "ASP"); Insert alert (insert) starting from the No. 0 position; Returns an empty array, alert (lang); Asp,php,javascript//replace var replace = Lang.splice ("C #", "Ruby"); Delete one item and insert two alert (lang); Asp,c#,ruby alert (replace); PHP, returning Deleted Items
var arr = new Array (6) arr[0] = "George" arr[1] = "John" arr[2] = "Thomas" arr[3] = "James" arr[4] = "Adrew" arr[5] = "Martin" do Cument.write (arr + "<br/>") Arr.splice (2,0, "William") document.write (arr + "<br/>")//output://george,john, Thomas,james,adrew,martin//george,john,william,thomas,james,adrew,martin
Reference: JS in Splice method http://www.studyofnet.com/news/937.html
The use of splice in JS