JavaScript Array Methods Cheat Sheet — Mutating vs Non-Mutating

Comprehensive guide to map, filter, reduce, find, some, every, slice, splice, and modern ES2023 non-mutating array helpers.

Transformation & Filtering (Immutable)

arr.map(x => x * 2)

Create a brand new array by applying callback function to every element

arr.filter(x => x > 10)

Return new array containing only elements that evaluate to truthy condition

arr.reduce((acc, curr) => acc + curr, 0)

Accumulate array values down to a single value (sum, object, or grouped array)

arr.flatMap(x => [x, x * 2])

Map each element and flatten the resulting array by 1 level

Searching & Validation

arr.find(item => item.id === targetId)

Return first matching element or undefined if not found

arr.some(x => x < 0)

Returns boolean true if at least 1 element meets condition

arr.every(x => typeof x === "string")

Returns boolean true only if ALL elements meet condition

arr.slice(1, 4)

Extract subset of array without mutating original array (start inclusive, end exclusive)