SyntaxStudy
Sign Up
JavaScript Intermediate 8 min read

Non-Mutating Array Methods

Non-Mutating Array Methods

Non-mutating (or non-destructive) array methods return a new array or value without altering the original. These are the foundation of functional programming patterns in JavaScript and are essential in frameworks that require immutable state updates.

map(fn)

Transforms each element by applying fn and returns a new array of the same length. The original is untouched.

filter(fn)

Returns a new array containing only elements for which fn returns a truthy value.

reduce(fn, initialValue)

Accumulates all elements into a single value by repeatedly calling fn(accumulator, currentValue). Versatile — it can implement map, filter, grouping, and more.

find, findIndex, some, every

  • find(fn) — returns the first matching element (or undefined)
  • findIndex(fn) — returns the index of the first match (or -1)
  • some(fn) — returns true if at least one element passes
  • every(fn) — returns true only if all elements pass
Example
const nums = [1, 2, 3, 4, 5, 6];
const doubled  = nums.map(n => n * 2);
const evens    = nums.filter(n => n % 2 === 0);
const sum      = nums.reduce((acc, n) => acc + n, 0);
const firstBig = nums.find(n => n > 3);
const idx      = nums.findIndex(n => n > 3);
console.log(doubled);   // [2,4,6,8,10,12]
console.log(evens);     // [2,4,6]
console.log(sum);       // 21
console.log(firstBig);  // 4
console.log(idx);       // 3
console.log(nums.some(n => n > 5));  // true
console.log(nums.every(n => n > 0)); // true
console.log(nums); // [1,2,3,4,5,6] — unchanged
Pro Tip

Chain filter and map to first narrow down a dataset then transform it — this pattern is cleaner than a single reduce that tries to do both at once.