Skip to content
transformation

map

Applies a projection function to each emitted value and passes the result downstream.

Signature

map<T, R>(project: (value: T, index: number) => R): OperatorFunction<T, R>

Marble Diagram

source:  --1----2----3----|
map(x => x * 2)
result:  --2----4----6----|

Example

import { of } from 'rxjs'
import { map } from 'rxjs/operators'

of(1, 2, 3).pipe(
  map(x => x * 2)
).subscribe(console.log)
// Output: 2, 4, 6

Common Use Cases

  • Transform API response shapes before passing to components
  • Extract a nested property from each emitted object
  • Format or normalise values (dates, currencies, strings)

Flow Diagram