Concat () [pure function]

The concat() method is used to merge two or more arrays without changing existing arrays.

const array1 = ['a'.'b'.'c'];
const array2 = ['d'.'e'.'f'];
const array3 = array1.concat(array2);
console.log(array3);
// ["a", "b", "c", "d", "e", "f"]
Copy the code

CopyWithin () [pure function]

The copyWithin() method shallowly copies part of an array to another location in the same array, without changing the length of the original array.

const array1 = ['a'.'b'.'c'.'d'.'e'];
console.log(array1.copyWithin(0.2.4));
// ["c", "d", "c", "d", "e"]First parameter: copied data, inserted at index position second parameter: start position of copied element third parameter: end position of copied elementCopy the code

entries()

The entries() method returns a new array iterator containing the key-value pairs for each index in the array. The return value is a new array iterator with a prototyped next method that can be used to iterate over the iterator to obtain the [key, value] of the original array.

var arr = ["a"."b"."c"];
var iterator = arr.entries();
iterator.next().value;
// [0, a];
// Use the for of loop
for (let [key, value] of iterator) {
    console.log(key, value);
}
// 0 'a' 1 'b' 2 'c'
Copy the code

every()

The every() method tests whether all elements in an array pass the test of a given function and always returns true if an empty array is passed

const arr = [];
arr.every((item, index) = > {
    // todo...
})
Copy the code

fill()

The fill() method fills an array with a fixed value from the start to the end of the index. The first argument: value the data to fill the second argument: startIndex the startIndex and the third argument: endIndex the endIndex

Filter () [pure function]

The filter() method returns the creation of a new array containing all the elements that have passed the test of the specified function, usually used to filter data, generating a new array and returning an empty array if none of the elements have passed the test

Find () [pure function]

The find() method returns the first value in the array that satisfies the provided function tests, otherwise undefined

FindIndex () [pure function]

The findIndex() method returns the index of the first element in the array that satisfies the provided function test, or -1 otherwise

Flat () [pure function]

The Flat () method iterates through the array recursively at a specified depth and merges all the elements with the elements in the traversed subarray into a new array. Returns: Specify the structural depth of the nested array to extract, defaults to 1

use`Infinity`You can expand nested arrays to any depthvar arr4 = [1.2[3.4[5.6[7.8[9.10]]]]];
arr4.flat(Infinity);
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]Reducer + concat forEach + concat + pushCopy the code

forEach()

The forEach() method performs the given function once on each element of the array

Array.from()

The array.from () method creates a new, shallow-copy instance of an array-like or iterable by creating an Array object as follows:

  1. To have alengthProperty and several index properties for any object
  2. Iterable objects (maps, sets, etc.)
console.log(Array.from('foo'));
// ["f", "o", "o"]
set //
const set = new Set(['foo'.'bar'.'baz'.'foo']);
Array.from(set);
// [ "foo", "bar", "baz" ]
map //
const map = new Map([[1.2], [2.4], [4.8]]);
Array.from(map);
// [[1, 2], [2, 4], [4, 8]]
Copy the code

includes()

The includes() method determines whether an array contains a specified value

indexOf()

The indexOf() method returns the first index in the array to find a given element, or -1 if none exists

Array.isArray()

The array.isarray () method is used to determine whether the value passed is an Array

join()

The join() method joins all the elements of an array into a string and returns the string

keys()

The keys() method returns an Array Iterator containing each key in the Array

lastIndexOf()

The lastIndexOf() method returns the index of the last element in the array, or -1 if none exists

map()

The map() method creates a new array, changing the return value of each element in the array after calling the provided function once

const arr = [1.2.3];
const newArr = arr.map(item= >...).Copy the code

Array.of()

The array.of () method creates a new Array instance with a variable number of arguments, regardless of the number or type of arguments. The difference between array.of () and the Array constructor is that:

  • Array.of(7)Create one with a single element7An array of
  • whileArray(7)Create an empty array of length 7 (an array with 7 Spaces instead of 7)undefinedComposing slave arrays)
Array.of(7);       / / [7]
Array.of(1.2.3); / / [1, 2, 3]

Array(7);          // [,,,,,,]
Array(1.2.3);    / / [1, 2, 3]
Copy the code

Pop () [change array length]

The pop() method removes the element following the group in the array and returns the value

push()

The push() method returns one or more elements added to the end of the array and returns the array’s new length

reduce()

The reduce() method performs the supplied reduce function on each element in the array and summarizes its results into a single return value

reduceRight()

The reduceRight() method accepts a function as an accumulator and each value of the array (from right to left)

Reverse () [change the original array]

The reverse() method reverses the elements in the array and returns the array

Shift () [change array length]

The shift() method removes the value of the first element from the array and returns the value of the changed element

Slice () [pure function]

The slice() method returns a new array object, starting with a shallow copy of the original array indexed to the end

Splice () [change the original array]

The splice() method modifies an array by deleting or replacing existing elements or adding existing elements in place, and returns the modified elements as an array

some()

The some() method tests whether at least one element in the array passes the provided test function and returns a Boolean

sort()

The sort() method sorts the elements of an array and returns the array, by default converting the elements to strings and then comparing their UTF-16 code unit values

If the sorting function is specified - if fun(a,b) <0, then a will be arranged before B - if fun(a,b) =0, then the positions of a and b remain the same - if fun(a,b) >0, then A will be placed after BCopy the code

toString()

The toString() method returns a string representing the specified array and its elements

Unshift ()[change the original array]

The unshift() method adds one or more elements to the beginning of the array and returns the new length of the array

values()

The values() method returns a new Array Iterator containing the value of each index of the Array