Course contentsShow
← JavaScript
Lesson 443 of 2,72312. Higher-Order FunctionsFree lesson

Chaining Map Operations

Composing multiple map calls to build complex transformations step by step.

Chaining Map Operations

What you'll learn: How to combine multiple map calls in sequence to build complex data transformations step by step.

The Core Idea

Since map always returns a new array, you can immediately call another map on that result. This is called chaining. Instead of storing intermediate arrays in variables, you chain transformations together in one expression.

Think of it like an assembly line: each map is a station that transforms the item passing through, and the output flows directly into the next station.

Basic Chaining Pattern

const numbers = [1, 2, 3, 4];

// Chained: multiply by 2, then add 10
const result = numbers
  .map(n => n * 2)
  .map(n => n + 10);

console.log(result); // [12, 14, 16, 18]

Each map gets the array from the previous operation. The first map doubles [1, 2, 3, 4] to [2, 4, 6, 8]. The second map adds 10 to get [12, 14, 16, 18].

Building Complexity Step by Step

Chaining lets you break complex transformations into simple, readable steps:

const names = ['alice', 'bob', 'charlie'];

const formatted = names
  .map(name => name.toUpperCase())
  .map(name => name + '!')
  .map(name => `Hello, ${name}`);

console.log(formatted);
// ['Hello, ALICE!', 'Hello, BOB!', 'Hello, CHARLIE!']

Each step does one clear job: uppercase, add punctuation, wrap in greeting.

Why This Works

Every map returns a brand new array, which itself has a map method. You're calling methods on the return values immediately—no magic, just method chaining.

Key Takeaway: Chain multiple map operations to break complex transformations into clear, sequential steps—each map receives the array output from the previous one.