The docs say
Pluck : Like map, but meant only for picking one of the nestedproperties of every emitted object.
Therefore, let's say you have
[ { name: 'Joe', age: 30, job: { title: 'Developer', language: 'JavaScript' } }, { name: 'Sarah', age: 35 }]
and you want a list of all job titles. pluck
returns
"Developer" , undefined
Using map
would be kind of a pain (because of the nullability of job
), but with 'pluck' you can write pluck('job', 'title')
and it will traverse the tree looking for job.title
- and won't fail if job
is null.
Example taken from : https://www.learnrxjs.io/learn-rxjs/operators/transformation/pluck
https://jsfiddle.net/btroncone/n592m597/
P.S: Please note that pluck
has been deprecated
Deprecation Notes
Use map and optional chaining: pluck('foo', 'bar') is map(x => x?.foo?.bar). Will be removed in v8.