Commonly used array

Pop: Removes the last primitive variation of an array, returning the deleted element

`

,1,2,3,4,5,6 var aa = [0] aa. Pop () / / 6 aa / / [0, 1, 2, 3, 4, 5]Copy the code

`

Push: Adds an element element to the end of an array

`

Aa,1,2,3,4,5,6 var aa = [0]. Push (' 99 ') / / / 0,1,2,3,4,5,6, "aa"Copy the code

`

Shift: Removes the first element of the array, returns the deleted element

`

,1,2,3,4,5,6 var aa = [0] aa. The shift () / / 0 aa / / [1, 2, 3, 4, 5, 6]Copy the code

`

Unshift: Inserts a value element first

`

Var aa = [0,1,2,3,4,5,6] aa.unshift(4) [99, 4, 0, 1, 2, 3, 4, 5, 6] aa.unshift(99)Copy the code

`

Slice: start, end of index Returns the truncated new array unchanged

`

Aa,1,2,3,4,5,6 var aa = [0]. Slice (2, 5) / / aa / [2, 3, 4] / [0, 1, 2, 3, 4, 5, 6]Copy the code

`

Splice: truncated index start, length, truncated bit insert new value old array change, return truncated new array,

`

,1,2,3,4,5,6 var aa = [0] aa. Splice (1, 2, '99') / / aa / [1, 2] / [0, "99", 3, 4, 5, 6]Copy the code

`

Reverse: Array arrangement in reverse such as string palindromes changes the original array

`

,1,2,3,4,5,6 var aa = [0] aa. The reverse () / / [6, 5, 4, 3, 2, 1, 0] aa / / [6, 5, 4, 3, 2, 1, 0]Copy the code

`

Sort: Changes the size of the original array

`

var aa = [3, 6, 2, 8, 3, 4, 81, 89, 4] aa.sort() || aa.sort((a,b)=>{ return a - b }) // [2, 3, 3, 4, 4, 6, 8, 81, 89] aa. Sort ((a, b) = > {return} b - a) / / [89, 81, 8, 6, 4, 4, 3, 3, 2) the original arrayCopy the code

`

Join: The array becomes a string (delimited by default ‘, ‘) without changing the group of elements

`

var aa = [2, 3, 3, 4, 4, 6, 8, 81, 89]

aa.join('||')  // "2||3||3||4||4||6||8||81||89"

aa  // [2, 3, 3, 4, 4, 6, 8, 81, 89]
Copy the code

`

Concat: returns a concatenated new array //a.concat(b) A /b array unchanged

`

var aa = [2, 3, 3, 4, 4, 6, 8, 81, 89]

var bb = ["22", "33", 577, "099"]

aa.concat(bb) // [2, 3, 3, 4, 4, 6, 8, 81, 89, "22", "33", 577, "099"]

bb.concat(aa)  // ["22", "33", 577, "099", 2, 3, 3, 4, 4, 6, 8, 81, 89]

aa // [2, 3, 3, 4, 4, 6, 8, 81, 89]

bb // ["22", "33", 577, "099"]
Copy the code

`