map() |
New array |
[1, 2, 3].map(x => x * 2) |
New array [2, 4, 6] |
Creates a new array by applying the function to each element of the array. |
filter() |
New array |
[1, 2, 3, 4].filter(x => x > 2) |
New array [3, 4] |
Filters the elements according to a condition and returns a new array. |
concat() |
New array |
[1, 2].concat([3, 4]) |
New array [1, 2, 3, 4] |
Adds multiple arrays and returns a new array. |
slice() |
New array |
[1, 2, 3, 4].slice(1, 3) |
New array [2, 3] |
Copies some elements from the specified index and returns a new array. |
join() |
String |
[1, 2, 3].join('-') |
String '1-2-3' |
Returns a string summing all the elements of the array. |
reverse() |
New array |
[1, 2, 3].reverse() |
New array [3, 2, 1] |
Reverses the elements of the array and returns a new array. |
includes() |
Boolean |
[1, 2, 3].includes(2) |
true |
checks whether the array contains a specified element. |
indexOf() |
Number (Index) |
[1, 2, 3].indexOf(2) |
1 |
Returns the first index of the specified element. |
find() |
First matched element |
[1, 2, 3].find(x => x > 1) |
2 |
Returns the first matching element. |
findIndex() |
Number (Index) |
[1, 2, 3].findIndex(x => x > 1) |
1 |
Returns the index of the first matching element. |
flat() |
New array |
[1, [2, 3], [4, 5]].flat() |
New array [1, 2, 3, 4, 5] |
Concatenates nested arrays inside arrays and returns a new array. |
flatMap() |
New array |
[1, 2].flatMap(x => [x, x * 2]) |
New array [1, 2, 2, 4] |
first implements map() then flattens. |
sort() |
New array |
[3, 1, 2].sort() |
New array [1, 2, 3] |
Sorts the elements of the array. |
every() |
Boolean |
[1, 2, 3].every(x => x > 0) |
true |
Returns true if all elements satisfy the condition, false otherwise. |
some() |
Boolean |
[1, 2, 3].some(x => x > 2) |
true |
Returns true if one or more elements satisfy the condition. |
reduce() |
Single value (like number) |
[1, 2, 3].reduce((acc, x) => acc x, 0) |
6 |
Returns a single value combining all elements of the array. |
reduceRight() |
Single value (like number) |
[1, 2, 3].reduceRight((acc, x) => acc x, 0) |
6 |
Like reduce() but works from right to left. |