Learn RxJS
Search…
pluck

signature: pluck(properties: ...args): Observable

Select property to emit.

New to transformation operators? Check out the article Get started transforming streams with map, pluck, and mapTo!

Examples

Example 1: Pluck object property
1
// RxJS v6+
2
import { from } from 'rxjs';
3
import { pluck } from 'rxjs/operators';
4
5
const source = from([
6
{ name: 'Joe', age: 30 },
7
{ name: 'Sarah', age: 35 }
8
]);
9
//grab names
10
const example = source.pipe(pluck('name'));
11
//output: "Joe", "Sarah"
12
const subscribe = example.subscribe(val => console.log(val));
Copied!
Example 2: Pluck nested properties
1
// RxJS v6+
2
import { from } from 'rxjs';
3
import { pluck } from 'rxjs/operators';
4
5
const source = from([
6
{ name: 'Joe', age: 30, job: { title: 'Developer', language: 'JavaScript' } },
7
//will return undefined when no job is found
8
{ name: 'Sarah', age: 35 }
9
]);
10
//grab title property under job
11
const example = source.pipe(pluck('job', 'title'));
12
//output: "Developer" , undefined
13
const subscribe = example.subscribe(val => console.log(val));
Copied!

Additional Resources

    pluck 📰 - Official docs
Last modified 1yr ago