Array Methods in JavaScript You Must Know

Published by Brayan K

A comprehensive guide to JavaScript array methods like map, filter, and reduce, with practical examples.

Arrays are the backbone of JavaScript. Whether you're building apps, games, dashboards, APIs, or full SaaS platforms, 80% of real-world JS coding involves arrays.

But many beginners only use for loops and .push() — missing out on powerful methods that simplify code, boost performance, and make you think like a professional JavaScript developer.

This guide covers every essential array method you must know, with simple explanations and real-use examples.

1. map() — Transform Each Item

map() creates a new array by applying a function to each element.

const numbers = [1, 2, 3];
const doubled = numbers.map(n => n * 2);

console.log(doubled); // [2, 4, 6]

Use when you need:

map() is the MOST used array method in modern JS.

2. filter() — Keep Only What You Need

filter() returns a new array containing only the elements that pass a condition.

const ages = [12, 18, 25, 30];
const adults = ages.filter(a => a >= 18);
// [18, 25, 30]

3. reduce() — Combine Everything Into One Value

reduce() is powerful. It converts an array into a single value (number, object, string, etc.).

const numbers = [1, 2, 3, 4];
const total = numbers.reduce((sum, n) => sum + n, 0);
// 10

4. forEach() — Loop Without Returning Anything

Used to run a function for each element.

["A", "B", "C"].forEach(letter => {
  console.log(letter);
});

Use when you don't need a returned array.

5. find() — Get the FIRST Match

Finds the first item that matches a condition.

const users = [
  { id: 1, name: "Alice" },
  { id: 2, name: "Boopie" }
];

const user = users.find(u => u.id === 2);
// { id: 2, name: "Boopie" }

6. findIndex() — Get the Index of the First Match

const index = users.findIndex(u => u.id === 2);
// 1

Useful when updating or deleting items inside an array.

7. some() — Does AT LEAST ONE Match?

const hasAdults = ages.some(a => a >= 18);

8. every() — Do ALL Items Match?

const valid = ages.every(a => a >= 18);

9. includes() — Quick Existence Check

["apple", "banana"].includes("banana"); // true

Faster and cleaner than manual loops.

10. sort() — Sort Arrays (but be careful!)

Sorts in place, meaning it modifies original array.

const nums = [4, 1, 3, 2];
nums.sort((a, b) => a - b);
// [1, 2, 3, 4]

Always use a compare function for numbers; otherwise results are wrong.

11. slice() — Copy or Extract Portions

const arr = [1, 2, 3, 4];
const firstTwo = arr.slice(0, 2);
// [1, 2], arr stays unchanged

Great for pagination or copying arrays.

12. splice() — Remove / Replace Items (Mutates!)

const arr = [1, 2, 3, 4];
arr.splice(1, 2);
// arr is now [1, 4]

Use carefully—it edits the original array.

13. flat() — Flatten Arrays

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

Helpful with nested API responses.

14. concat() — Merge Arrays

const merged = arr1.concat(arr2);

15. join() — Convert Array to String

["A", "B", "C"].join("-");
// "A-B-C"

Essential for CSV, logs, and UI formatting.

When to Use Which Method? (Quick Guide)

GoalBest Method
Transform arraymap
Keep only some itemsfilter
Combine all itemsreduce
Loop onlyforEach
Find 1 itemfind
Check if existssome / includes
Validate all itemsevery
Sortsort
Create copyslice
Modify originalsplice

Conclusion

Mastering these array methods will instantly:

These are the exact tools used by:

Related articles

Related lessons