Every common JavaScript array method, grouped by behavior: whether it mutates, what it returns, and when to reach for it. A quick-reference for the methods you use every day.
Array methods come in two kinds. Mutating methods change the array you call them on, while non-mutating methods return a new array and leave the original alone. When you can, prefer non-mutating methods: they avoid surprise side effects and they chain cleanly. map, filter, and reduce are the workhorses you will reach for every day. map transforms each item, filter keeps the items you want, and reduce folds the whole array into a single value.
Reference table · 40 entries
JavaScript Array MethodsExplained
40 of 40 rows
Mutating
Yes
new length
Add one or more items to the end of the array.
Yes
value | undefined
Remove and return the last item.
Yes
value | undefined
Remove and return the first item.
Yes
new length
Add one or more items to the start of the array.
Yes
removed items array
Insert, remove, or replace items starting at an index.
Yes
same array, sorted
Reorder items in place; without a compare function, items are compared as strings.
Yes
same array, reversed
Flip the order of items in place.
Yes
same array
Overwrite a range of slots with one value.
Yes
same array
Copy a run of items to another position inside the same array.
Iteration / transform
No
new array
Transform every item into something new.
No
new array
Keep only the items that pass a test.
No
accumulator
Collapse all items into a single value.
No
accumulator
Collapse all items into a single value, starting from the last item.
No
undefined
Run a side effect for every item.
No
value | undefined
Get the first item that passes a test.
No
index or -1
Get the index of the first item that passes a test.
No
value | undefined
Get the last item that passes a test.
No
index or -1
Get the index of the last item that passes a test.
No
boolean
Check if at least one item passes a test.
No
boolean
Check if all items pass a test.
No
new array
Flatten nested arrays up to a given depth; pass Infinity to flatten every level.
No
[index, value] iterator
Iterate over index and value pairs.
No
index iterator
Iterate over the indexes only.
No
value iterator
Iterate over the values only.
Accessor / non-mutating
No
new array
Copy a portion of the array into a new array.
No
new array
Merge two or more arrays into one.
No
boolean
Check if a value exists in the array.
No
index or -1
Find the first index of a value.
No
index or -1
Find the last index of a value.
No
string
Glue all items into one string with a separator.
No
value | undefined
Read an item by index, where a negative index counts from the end.
Newer
No
new array
Map each item and flatten the result one level in one pass.
No
new array
Return a copy with one index replaced.
No
new array, sorted
Sort a copy and leave the original array intact.
No
new array, reversed
Reverse a copy and leave the original array intact.
No
new array
Splice a copy and leave the original array intact.
Statics
No
new array
Build an array from an iterable or an array-like object.