Skip to content

JavaScript Array Methods Explained

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
40 of 40 rows
Mutating
Yesnew lengthAdd one or more items to the end of the array.
Yesvalue | undefinedRemove and return the last item.
Yesvalue | undefinedRemove and return the first item.
Yesnew lengthAdd one or more items to the start of the array.
Yesremoved items arrayInsert, remove, or replace items starting at an index.
Yessame array, sortedReorder items in place; without a compare function, items are compared as strings.
Yessame array, reversedFlip the order of items in place.
Yessame arrayOverwrite a range of slots with one value.
Yessame arrayCopy a run of items to another position inside the same array.
Iteration / transform
Nonew arrayTransform every item into something new.
Nonew arrayKeep only the items that pass a test.
NoaccumulatorCollapse all items into a single value.
NoaccumulatorCollapse all items into a single value, starting from the last item.
NoundefinedRun a side effect for every item.
Novalue | undefinedGet the first item that passes a test.
Noindex or -1Get the index of the first item that passes a test.
Novalue | undefinedGet the last item that passes a test.
Noindex or -1Get the index of the last item that passes a test.
NobooleanCheck if at least one item passes a test.
NobooleanCheck if all items pass a test.
Nonew arrayFlatten nested arrays up to a given depth; pass Infinity to flatten every level.
No[index, value] iteratorIterate over index and value pairs.
Noindex iteratorIterate over the indexes only.
Novalue iteratorIterate over the values only.
Accessor / non-mutating
Nonew arrayCopy a portion of the array into a new array.
Nonew arrayMerge two or more arrays into one.
NobooleanCheck if a value exists in the array.
Noindex or -1Find the first index of a value.
Noindex or -1Find the last index of a value.
NostringGlue all items into one string with a separator.
Novalue | undefinedRead an item by index, where a negative index counts from the end.
Newer
Nonew arrayMap each item and flatten the result one level in one pass.
Nonew arrayReturn a copy with one index replaced.
Nonew array, sortedSort a copy and leave the original array intact.
Nonew array, reversedReverse a copy and leave the original array intact.
Nonew arraySplice a copy and leave the original array intact.
Statics
Nonew arrayBuild an array from an iterable or an array-like object.
Nonew arrayBuild an array from a list of arguments.
NobooleanCheck whether a value is a true array.
Nopromise of a new arrayBuild an array from an async iterable.