Curriculum / Intermediate / Lesson 16

Array Methods: map, filter, reduce

The three methods that replace most manual loops.

16 of 30
intermediate 📖 8 min read 🎯 4 questions

Why Use These Methods?

map(), filter(), and reduce() are functional programming methods that replace most manual loops. They make your code more readable, less error-prone, and often shorter.

💡 Key insight These methods don't modify the original array — they return new arrays (or a single value for reduce).

map() — Transform Every Element

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

let numbers = [1, 2, 3, 4, 5];
let doubled = numbers.map(n => n * 2);
// [2, 4, 6, 8, 10]

filter() — Keep Only Some Elements

filter() creates a new array with only elements that pass a test.

let numbers = [1, 2, 3, 4, 5, 6];
let evens = numbers.filter(n => n % 2 === 0);
// [2, 4, 6]

reduce() — Reduce to a Single Value

reduce() accumulates array elements into a single value.

let numbers = [1, 2, 3, 4, 5];
let sum = numbers.reduce((acc, curr) => acc + curr, 0);
// 15

Common Mistakes

Quick Quiz

1. What does map() do?

2. Which method would you use to get only even numbers from an array?

3. What does reduce() return?

Summary

Back to curriculum