Hiprup

What are the most important Array methods in JavaScript?

The most-used array methods fall into a few groups. Most are non-mutating (they return a new array), which keeps data predictable.

  • Transforming — map (transform each item), filter (keep matching items), reduce (combine into one value).

  • Searching — find, findIndex, includes, some, every.

  • Iterating — forEach runs a function per item.

  • Adding / removing — push, pop, shift, unshift (these mutate); slice and concat don't.

  • Ordering — sort and reverse (both mutate, so copy first).

Tip: prefer non-mutating methods (map, filter, slice) to avoid accidentally changing the original array.

const users = [
  { name: 'Alice', age: 25, active: true },
  { name: 'Bob', age: 30, active: false },
  { name: 'Charlie', age: 35, active: true }
];

// map — transform
const names = users.map(u => u.name); // ['Alice', 'Bob', 'Charlie']

// filter — select
const active = users.filter(u => u.active); // [Alice, Charlie]

// find — first match
const bob = users.find(u => u.name === 'Bob'); // { name: 'Bob', ... }

// reduce — aggregate
const totalAge = users.reduce((sum, u) => sum + u.age, 0); // 90

// some / every — test
const hasInactive = users.some(u => !u.active);  // true
const allActive = users.every(u => u.active);      // false

// Chaining
const activeNames = users
  .filter(u => u.active)
  .map(u => u.name)
  .sort(); // ['Alice', 'Charlie']

// flat / flatMap
const nested = [[1, 2], [3, 4], [5]];
console.log(nested.flat());  // [1, 2, 3, 4, 5]

const sentences = ['hello world', 'foo bar'];
const words = sentences.flatMap(s => s.split(' ')); // ['hello', 'world', 'foo', 'bar']

// Non-mutating (ES2023)
const sorted = users.toSorted((a, b) => a.age - b.age); // New array
const reversed = [1, 2, 3].toReversed(); // [3, 2, 1] — original unchanged

map transforms each element. filter keeps matching elements. find returns the first match. reduce accumulates a single value. some/every test conditions. Chaining combines operations. flatMap combines map and flat. toSorted/toReversed (ES2023) create new arrays instead of mutating.

These methods cover 95% of array operations without explicit loops.

Know the top 10: map, filter, reduce, find, findIndex, some, every, flat, flatMap, forEach. Show chaining (filter+map+sort).

Know which methods mutate (sort, reverse, splice, push) vs return new arrays (map, filter, flat, toSorted). reduce is the most versatile — it can implement any other array method.

What are the most important Array methods in JavaScript? | Hiprup