JavaScript Array Methods Reference
Every Array.prototype method that matters — with the syntax you'll actually type, real examples, and the mutating-vs-non-mutating gotcha for each one. Grouped by what you're trying to do.
Iteration
Array.prototype.forEach
Executes a provided callback once for each array element, in ascending order. Reach for it when you need side effects (logging, DOM updates, pushing to another store) and do not need a return value.
Array.prototype.map
Creates a new array populated with the results of calling a callback on every element of the calling array. Reach for it whenever you want to transform each element 1-to-1 into a new value.
Array.prototype.filter
Creates a new array containing every element for which the callback returned a truthy value. Reach for it to pare a list down to items matching a predicate.
Array.prototype.reduce
Runs a reducer function on each element, left-to-right, folding the array into a single accumulated value. Reach for it to sum/product/group/build an object or any custom fold.
Array.prototype.some
Returns true if the callback returns truthy for at least one element, short-circuiting on the first hit. Reach for it to answer "does anything match?" without walking the full array.
Array.prototype.every
Returns true only if the callback returns truthy for every element, short-circuiting on the first falsy result. Reach for it to validate that all items meet a condition.
Transformation
Array.prototype.flat
Returns a new array with all sub-array elements concatenated up to the specified depth (ES2019). Reach for it to unnest arrays of arrays without a manual reduce.
Array.prototype.flatMap
Maps each element with a callback, then flattens the result by one level (ES2019). Reach for it when a mapper naturally returns arrays and you want a single flat list back.
Array.prototype.sort
Sorts the array in place and returns the same array; without a compareFn elements are coerced to strings and sorted lexicographically. Reach for it when you need ordered data — but always pass a compareFn for numbers.
Array.prototype.reverse
Reverses the order of elements in place and returns the same (mutated) array. Reach for it when you truly want to reverse the source; otherwise use toReversed().
Search & Test
Array.prototype.find
Returns the first element for which the callback returns truthy, or undefined if none match. Reach for it when you need the matching item itself, not just its index.
Array.prototype.findIndex
Returns the index of the first element for which the callback returns truthy, or -1 if none match. Reach for it when you need the position — e.g. to splice or replace.
Array.prototype.findLast
Walks the array from the END and returns the last element for which the callback returns truthy (ES2023). Reach for it when the most recent matching entry is what you want.
Array.prototype.indexOf
Returns the first index where searchElement is strictly equal (===) to an array item, or -1. Reach for it for a fast, exact primitive lookup — but not for objects or NaN.
Array.prototype.includes
Returns true if the array contains searchElement using SameValueZero equality (ES2016). Reach for it as the readable boolean alternative to `indexOf(x) !== -1`.
Mutation (Modifies Original)
Array.prototype.push
Appends one or more elements to the end of the array and returns the new length. Reach for it to grow a list — it's the canonical "add to the end" call.
Array.prototype.pop
Removes the last element from the array and returns it (or undefined if empty). Reach for it to consume the tail of a list — the natural pair to push for stack behavior.
Array.prototype.shift
Removes the first element from the array and returns it, reindexing every remaining element. Reach for it to consume the head of a list — the natural queue operation.
Array.prototype.unshift
Prepends one or more elements to the front of the array and returns the new length. Reach for it to insert at the head — but be aware every existing item is reindexed.
Array.prototype.splice
Removes and/or inserts elements at any position in the array, returning the removed items. Reach for it to do insert/delete/replace edits in one call.
Inspection
Array.prototype.at
Returns the element at the given integer index, supporting negative values that count from the end (ES2022). Reach for it as the clean replacement for `arr[arr.length - 1]`.
Array.prototype.slice
Returns a shallow copy of a portion of the array from start (inclusive) to end (exclusive) without modifying the source. Reach for it to extract a range or to clone an array (`arr.slice()`).
Array.prototype.concat
Returns a new array formed by joining the source with the provided arrays and/or values (one level of spread). Reach for it to merge arrays without mutating any of them.
Array.prototype.join
Returns a string formed by concatenating each element, separated by the given string (default ','). Reach for it to build CSV/URL/paths or any delimited string from an array.
Creation
Array.from
Creates a new Array from an iterable or array-like object, optionally mapping each element as it is copied (ES2015). Reach for it to materialize a NodeList, Set, string, or `{length}` array-like into a real array.
Array.isArray
Returns true if the value is an Array (works across realms/iframes, unlike `instanceof Array`). Reach for it as the canonical type check before running array-only methods.