Array Methods

map, filter, reduce

Lesson 82
+30 XP
Step 1 of 5

Powerful Array Methods

JavaScript arrays have powerful built-in methods that transform data efficiently. The three most important are map, filter, and reduce.

Key Concept: These methods don't modify the original array. They create new arrays or values based on transformations you define.

Overview:

.map() - Transform Each Item

Creates a new array by applying a function to each element.

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

.filter() - Keep Certain Items

Creates a new array with only items that pass a test.

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

.reduce() - Combine Into One Value

Reduces an array to a single value (sum, product, object, etc.).

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