6 Must-Know JavaScript Array Methods (With Simple Examples)

Javascript provides us with many array methods but only a handful are used consistently in real-world code. So in this post, we will see the 6 most essential array methods, along with simple diagrams and clear examples to make it easier and straightforward to understand.

The Main 6 Array Methods

These are the methods you’ll encounter the most when transforming, filtering, looping, and searching through collections:

MethodWhat It DoesExample
map()Transform each item[1,2,3].map(n => n * 2)[2,4,6]
filter()Keep only elements matching a condition[1,2,3,4].filter(n => n % 2 === 0)
reduce()Combine the array into a single value[1,2,3].reduce((a,n) => a+n, 0)
find()Return the first matching elementusers.find(u => u.id === 2)
includes()Check if a primitive value exists[1,2,3].includes(2)
forEach()Loop for side effects[1,2,3].forEach(console.log)

Which Method Should You Use?

When working with arrays, it helps to think in terms of intent:

js-arrays-diagram

Method-by-Method Breakdown

1. map() → Transform Each Value

// map() takes your array, applies a transformation to every item, and returns a brand-new array
const numbers = [1, 2, 3];
const doubled = numbers.map(n => n * 2); 
// Output: [2, 4, 6]

Use it when:

  • You want the same number of elements
  • You’re transforming values: formatting text, adding flags, extracting fields, converting types, etc.

2. filter() → Keep Only What Matches

// filter() returns a new array containing only the elements that satisfy a condition
const evens = [1, 2, 3, 4].filter(n => n % 2 === 0);
// Output: [2, 4]

Use it when:

  • You’re removing unwanted items
  • You’re validating or sanitizing lists
  • You need a subset of the original array

3. reduce() → Accumulate Into a Single Value

// reduce() takes each value and combines it into one final output: a number, an object, an array, or any other structure
const sum = [1, 2, 3, 4].reduce((acc, n) => acc + n, 0);
// Output: 10

Use it when:

  • You want totals, minimums, maximums
  • You’re building objects or maps
  • You’re transforming data into a single result

4. find() → Get the First Matching Element

// find() returns the first element that matches your condition and stops early
const user = users.find(u => u.id === 2);

Use it when:

  • You expect only one match
  • You want the actual object, not a filtered array
  • You want the search to stop early once found

5. includes() → Check Existence

// includes() checks if a primitive value (string, number, boolean) exists inside an array
[1, 2, 3].includes(2); // true

Use it when:

  • You only need a yes/no answer
  • You’re checking for common values like IDs, tags, or flags

6. forEach() → Loop for Side Effects

// Use it when you’re not transforming or filtering, just doing something with each value
[1, 2, 3].forEach(n => console.log(n));

Use it for:

  • Logging
  • Mutating existing objects
  • DOM updates
  • External calls (APIs, analytics, etc.)

Not recommended for building new arrays, use map() or filter() instead.

Mutating vs Non-Mutating Methods

One of the biggest pitfalls for newer developers is knowing which methods modify the original array.

CategoryMethodsMutates?
Non-Mutatingmap, filter, reduce, slice, concatNo
Mutatingpush, pop, shift, unshift, splice, sort, reverse, fillYes

Why it matters: mutating methods can cause hard-to-debug side effects, especially in React or functional codebases.

Quick Tips for Using Array Methods

1. Prefer non-mutating methods

They’re safer, more predictable, and play nicer with modern frameworks.

2. Method chaining: Your superpower

const total = items
  .filter(x => x.active)
  .map(x => x.value)
  .reduce((sum, v) => sum + v, 0);

3. Understand early-exit behavior

  • find()stops early
  • includes()stops early
  • forEach() and map()do NOT stop early

4. Performance basics

  • map, filter, forEach → O(n)
  • sort → O(n log n)
  • reduce → O(n), but can replace multiple loops

Final Thoughts

Mastering these methods can level-up your Javascript skills and improve the quality of your code. Using these methods make your code:

  • More expressive
  • Less error-prone
  • More maintainable
  • Easier to read

Next Up: Full list of Javascript Array Methods

Don’t miss the next post where we will break down the majority of Javascript array methods.

Happy learning and thank you for reading!