What are the commonly used methods of arrays in ES6?
There are several commonly used methods for arrays in ES6.
- forEach(): perform a specified operation on each element in an array.
- map() creates a new array where the elements are the result of a specified operation applied to each element of the original array.
- filter(): creates a new array with elements that meet a specific condition from the original array.
- find(): return the first element in the original array that satisfies the specified condition.
- findIndex(): returns the index value of the first element in the original array that meets the specified condition.
- some(): Determines if at least one element in the original array satisfies a specified condition.
- every() determines whether all elements of the original array satisfy a specified condition.
- reduce(): Perform a specified merging operation on all elements in the original array and return the merged result.
- reduceRight() performs a specified merging operation on all elements of the original array from right to left and returns the resulting merged value.
- sort(): arrange the original array in order.
- reverse(): reverse the order of elements in the original array.
- includes(): Determines whether the original array contains a specified element.
- indexOf(): returns the index of the first occurrence of a specified element in the original array.
- lastIndexOf(): Returns the index of the last occurrence of a specified element in the original array.
- slice() returns a portion of the original array.
- splice(): perform insert, delete, and update operations on the original array.
- concat(): Combines multiple arrays into a single new array.
- join(): Concatenate all elements in the original array into a single string with a specified separator.
- fill(): Fill the original array with the specified value.
- Array.from() converts an array-like object or iterable object into an array.
The above are commonly used methods in ES6 for arrays, which can be used for various operations and processing on arrays.