rxjs / 7.5.5 / api / index / function / pluck.html /

pluck

function deprecated operator

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>

Parameters

properties (string | number | symbol)[]

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, pluck } from 'rxjs';

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 K1

Returns

OperatorFunction<T, T[K1]>

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

Parameters

k1 K1
k2 K2

Returns

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

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

Parameters

k1 K1
k2 K2
k3 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 K1
k2 K2
k3 K3
k4 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 K1
k2 K2
k3 K3
k4 K4
k5 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 K1
k2 K2
k3 K3
k4 K4
k5 K5
k6 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 K1
k2 K2
k3 K3
k4 K4
k5 K5
k6 K6
rest string[]

Returns

OperatorFunction<T, unknown>

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

Parameters

properties string[]

Returns

OperatorFunction<T, unknown>

See Also

© 2015–2022 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/index/function/pluck