pluck

function deprecated

Maps each source value to its specified nested property.

Deprecation Notes

Use map and optional chaining: pluck('foo', 'bar') is map(x => x?.foo?.bar). Will be removed in v8.

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

Deprecation Notes

Use map and optional chaining: pluck('foo', 'bar') is map(x => x?.foo?.bar). Will be removed in v8.

Parameters

properties

The nested properties to pluck from each source value.

Returns

OperatorFunction<T, R>: A function that returns an Observable of property values from the source values.

Description

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

pluck marble diagram

Given a list of strings or numbers describing a path to a 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(k1: K1, k2: K2, k3: K3, k4: K4, k5: K5, k6: K6, ...rest: string[]): OperatorFunction<T, unknown>

Parameters

k1

Type: K1.

k2

Type: K2.

k3

Type: K3.

k4

Type: K4.

k5

Type: K5.

k6

Type: K6.

rest

Type: string[].

Returns

OperatorFunction<T, unknown>

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

Parameters

properties

Type: string[].

Returns

OperatorFunction<T, unknown>

See Also

© 2015–2021 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