Efficient-angular
GitHubToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeBack to homepage

Map

Applies a given project function to each value emitted by the source Observable, and emits the resulting values as an Observable.

Syntax

map<T, R>(project: (value: T, index: number) => R, thisArg?: any): OperatorFunction<T, R>
ParametersDescription
projectThe function to apply to each value emitted by the source Observable. The index parameter is the number i for the i-th emission that has happened since the subscription, starting from the number 0.
thisArg OptionalDefault is undefined. An optional argument to define what this is in the project function.

Returns

OperatorFunction<T, R>: A function that returns an Observable that emits the values from the source Observable transformed by the given project function.

Example

Map every click to the clientX position of that click

import { fromEvent } from 'rxjs';
import { map } from 'rxjs/operators';

const clicks = fromEvent(document, 'click');
const positions = clicks.pipe(map(ev => ev.clientX));
positions.subscribe(x => console.log(x));