It changes the original array

Reverse (). Array flipping, which reverses the positions of elements in an array

Let a = [1, 2, 3, 4, 5] let b = a.r everse () / / b [5, 4, 3, 2, 1] a / / [5, 4, 3, 2, 1] after the return value is the reverse of the arrayCopy the code

Sort (). Sorts the elements in an array, but the default sort order is by string Unicode code points

Let a=[1,22,3,24,15] let b= a.secort () b //[1, 15, 22, 24, 3] a //[1, 15, 22, 24, 3Copy the code

Pop (). Removes the last element in the array

var a1 = [1, 2, 3, 4]; A1. Pop () //4 a1//[1, 2, 3] returns the deleted elementCopy the code

Push (). Adds one or more elements to the end of the array

var a1 = [1, 2, 3, 4]; Var a1 = [1, 2, 3, 4]; A1. Push (1,2,3) //7 a1 //[1, 2,3,4, 1,2,3] returns the length of the array after the insertCopy the code

Shift (). Deletes the first element in the array

var a1 = [1, 2, 3, 4]; A1. Shift () //1 a1 //[2, 3, 4] returns the deleted elementCopy the code

Unshift (). Adds one or more elements to the head of the array

var a1 = [1, 2, 3, 4]; Unshift () var a1 = [1, 2, 3, 4]; Unshift (1,2,3) //7 a1 //[1, 2,3, 1,2,3, 4] Adds one or more elements to the head of the arrayCopy the code

Splice (). With the function of [add] [delete] [change], concrete examples show 👇

Var a1 = [1, 2, 3, 4]; A1. Splice (2, 0, 'insert') / / [] returns an empty array a1 / / [1, 2, "insert", 3, 4] / / delete the var a1 = [1, 2, 3, 4]. Var a1 = [1, 2, 3, 4]; var a1 = [1, 2, 3]; A1. Splice (2, 1, 'change') / / [3] returns the elements of the substituted delete a1 / / [1, 2, "change", 4)Copy the code

Fill (). Fills an array with the given value

Accept the second and third parameters, Respectively is used to specify the starting position and the end of filling position/var/three parameters a1 = [' a ', 'b', 'c'] a1. The fill (7, 1, 2) / / [7, "a", "c"] a1 / / [7, "a", "C"] / var / 1 parameter a1 = [' a ', 'b', 'c'] a1. The fill (7) / / [7, "a", "c"] a1 / / [7, 7, 7) after the return value is filling the arrayCopy the code

Do not change the original array

Jion (). Converts an array to a string

Var a = [1, 2, 3, 4, 5] var b = a. oin (' - ') b / / the return value "of" the 1-2-3-4-5 a / / [1, 2, 3, 4, 5] the return value is the string after a switchCopy the code

Concoat (). Merge arrays

Let a =,22,3,24,15 [1] let c = [1, 2, 3] let b = a.c oncat (c) a / / [1, 22, 3, 24, 15] / / b [1, 22, 3, 24, 15, 1, 2, 3] c / / [1, 2, 3] The return value is the new array generated by the mergeCopy the code

Slice (). Truncates a portion of an array from start to end. The second argument is optional and does not write to or greater than the length of the array

Let a=[1,22,3,24,15] let b=a.slice(1,1) b //undefined constant A =[1,22,3,24,15] let b= a.ice (1) b //[22, 3,24,15] returns the truncated arrayCopy the code

Map (). Each element in the new array executes the corresponding function for each element in the original array

Let a=[1,22,3,24,15] let b=a.map(item=>item*2) a //[1, 22,3,24,15] b //[2, 44, 6, 48, 30Copy the code

Filter (). Filter criteria generate a new array

Let a = [1, 4-trichlorobenzene, '] let b = a.f ilter (item = > item > 1)/b/a / / [2, 4] [1, 2, 4, ""] the return value is the filter conform to the conditions of the new arrayCopy the code

Every (). Checks whether every element in the array matches the criteria, and returns true if all elements match, false if any element does not match, and true if the array is empty

Let a=[1,22,3,24,15] let b= a.very (item=>item>15) b // false let a=[1,22,3,24,15] let b= a.very (item=>item>1) b // true  a //[1, 22, 3, 24, 15] let a=[] let b=a.every(item=>item) b //trueCopy the code

ForEach (). Returns no value and does not alter the array. This method loops through each element of the array and executes the corresponding callback

/ / forEach let a = ({name: 'Joe, the order: 0}, {name: "bill", the order: 1}, {name:' Cathy ', Order :2}] let obj1Name a.freach (item=>{if(item.order==1){obj1Name=item.name}}) console.log(obj1Name) // / / filter let a = ({name: 'Joe, the order: 0}, {name: "bill", the order: 1}, {name:' Cathy ', Order :2}] let obj1Name obj1Name=a.filter(item=>{return item.order==1}) console.log(obj1Name) //[{name: "",order: 1}]Copy the code

Reduce (). Acts as an accumulator. The first argument represents the last cumulative return value, and the second argument represents the current return value

const array1 = [1, 2, 3, 4]; const reducer = (prev, curr) => prev + curr; // 1 + 2 + 3 + 4 console.log(array1.reduce(reducer)); // 10 // 5 + 1 + 2 + 3 + 4 console.log(array1.reduce(reducer, 5)); / / 15Copy the code

Find (). Find the first element in the array that matches the callback argument. Each element executes the callback argument in turn

var a1=[1, 4, -5, 10]
a1.find((n) => n < 0)   // -5
a1  //[1, 4, -5, 10]

var a1=[1, 4, -5, 10]
a1.find((n) => n == 0)   // undefined
a1  //[1, 4, -5, 10]
Copy the code

FindIndex (). The use of the findIndex method on an array instance is very similar to that of find. Returns the index position if the first eligible array member is found, or -1 if all members do not

/ / not conform to the element var a1 = [1, 4, 5, 10] a1. FindIndex (n) = > (n = = 0) a1 / / / / - 1 [1, 4, 5, 10] / / have meet element var a1 = [1, 4, 5, 10] a1.findIndex((n) => n <0) //2Copy the code

Includes (). Determines whether the array contains the given value

Let a1=[1,2,3] let a2=1 let A3 =4 a1.includes(a2) //true a1.includes(a3) //false The return value is a Boolean valueCopy the code

Entries ().keys ().values (). Used to traverse a number group and returns an traverser object, which can be accessed by using the for… Of traverses

for (let index of ['a', 'b'].keys()) { console.log(index); } // 0 // 1 for (let elem of ['a', 'b'].values()) { console.log(elem); } // 'a' // 'b' for (let [index, elem] of ['a', 'b'].entries()) { console.log(index, elem); } Keys are traversal of keys values are traversal of values Entries are traversal of keys and values togetherCopy the code

Read some articles, summary, welcome to correct the text error