W3cubDocs

/RxJS

pluck

function stable

Maps each source value (an object) to its specified nested property.

pluck<T, R>(...properties: string[]): OperatorFunction<T, R>

Parameters

properties

The nested properties to pluck from each source value (an object).

Returns

OperatorFunction<T, R>: A new Observable of property values from the source values.

Description

Like map, but meant only for picking one of the nested properties of every emitted object.

pluck marble diagram

Given a list of strings describing a path to an object property, retrieves the value of a specified nested property from all values in the source Observable. If a property can't be resolved, it will return undefined for that value.

Example

Map every click to the tagName of the clicked target element

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

const clicks = fromEvent(document, 'click');
const tagNames = clicks.pipe(pluck('target', 'tagName'));
tagNames.subscribe(x => console.log(x));

Overloads

pluck(k1: K1): OperatorFunction<T, T[K1]>

Parameters

k1

Type: K1.

Returns

OperatorFunction<T, T[K1]>

pluck(k1: K1, k2: K2): OperatorFunction<T, T[K1][K2]>

Parameters

k1

Type: K1.

k2

Type: K2.

Returns

OperatorFunction<T, T[K1][K2]>

pluck(k1: K1, k2: K2, k3: K3): OperatorFunction<T, T[K1][K2][K3]>

Parameters

k1

Type: K1.

k2

Type: K2.

k3

Type: K3.

Returns

OperatorFunction<T, T[K1][K2][K3]>

pluck(k1: K1, k2: K2, k3: K3, k4: K4): OperatorFunction<T, T[K1][K2][K3][K4]>

Parameters

k1

Type: K1.

k2

Type: K2.

k3

Type: K3.

k4

Type: K4.

Returns

OperatorFunction<T, T[K1][K2][K3][K4]>

pluck(k1: K1, k2: K2, k3: K3, k4: K4, k5: K5): OperatorFunction<T, T[K1][K2][K3][K4][K5]>

Parameters

k1

Type: K1.

k2

Type: K2.

k3

Type: K3.

k4

Type: K4.

k5

Type: K5.

Returns

OperatorFunction<T, T[K1][K2][K3][K4][K5]>

pluck(k1: K1, k2: K2, k3: K3, k4: K4, k5: K5, k6: K6): OperatorFunction<T, T[K1][K2][K3][K4][K5][K6]>

Parameters

k1

Type: K1.

k2

Type: K2.

k3

Type: K3.

k4

Type: K4.

k5

Type: K5.

k6

Type: K6.

Returns

OperatorFunction<T, T[K1][K2][K3][K4][K5][K6]>

pluck(...properties: string[]): OperatorFunction<T, R>

Parameters

properties

Type: string[].

Returns

OperatorFunction<T, R>

See Also

© 2015–2018 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/operators/pluck