Methods in ES6 array

Array creation

Array.of()
takes all the values ​​in the parameter as elements to form an array.
Array.from()
converts an array-like object or iterable object into an array.
The parameter
Array.from(arrayLike[, mapFn[, thisArg]])
returns the converted array.
The
array-like object or iterable object that arrayLike wants to convert.
mapFn is
optional. The map function is used to process each element. The processed elements are put into the array.
thisArg is
optional, used to specify the this object when the map function is executed.

Array-like object

一个类数组对象必须含有 length 属性,且元素属性名必须是数值或者可转换为数值的字符。 转换可迭代对象

Extension method

Find
find()
finds the elements that meet the conditions in the array. If there are multiple elements that meet the conditions, it returns the first element.
findIndex()
finds the index of the eligible element in the array. If there are multiple eligible elements, it returns the index of the first element.
Fill
fill()
fills the contents of array elements with a certain range of indexes into a single specified value.
copyWithin()
modifies an array element with a certain range index to this array element with another specified range index.
Traverse
entries()
Traverse key-value pairs.
keys()
iterates over the key names.
values()
iterates over key values.
Include whether the
includes()
array contains the specified value.
flat()
nested array to one-dimensional array
flatMap()
first processes each element in the array, and then executes the flat() method on the array.

Spread operator
copy array […a]
merge array […a,…b]

Guess you like

Origin blog.csdn.net/zxlong020/article/details/108477716