Add element to array (end) push element

var arr = []; arr.push(100); arr.push(99); arr.push(101); alert(arr); / / 100,99,101Copy the code

Add the element to the header

var arr = [];
arr.splice(0.0.100);//splice(index,howmany,item1...
/* index required. Integer to specify where items are added/removed, and negative numbers to specify positions from the end of the array. Howmany required. Number of items to delete. If set to 0, the project will not be deleted. item1, ... ItemX is optional. The new item added to the array. * /
Copy the code

End element pop()

var arr = []; arr.push(100); arr.push(99); arr.push(101); alert(arr); / / 100,99,101 arr. Pop (); alert(arr); / / 13 100Copy the code

Shift ()

var arr = []; arr.push(100); arr.push(99); arr.push(101); alert(arr); / / 100,99,101 arr. Shift (); alert(arr); / / 99101Copy the code

Splice (start position, length)

var arr = []; arr.push(100); arr.push(99); arr.push(101); alert(arr); / / 100,99,101 arr. Splice (1, 1); alert(arr); / / 100101Copy the code
var arr = []; arr.push(100); arr.push(99); arr.push(101); alert(arr); / / 100,99,101 arr. Splice (1, 2); alert(arr); / / 100Copy the code

Combine with search

var arr = []; arr.push(100); arr.push(99); arr.push(101); alert(arr); / / 100,99,101 arr. Splice (arr. IndexOf (99), 1); alert(arr); / / 100101Copy the code