pluck

연산자(operator) 정의: pluck(properties: ...args): Observable

Select properties to emit.

Examples

Example 1: Pluck object property

( jsBin | jsFiddle )

const source = Rx.Observable.from([
  {name: 'Joe', age: 30},
  {name: 'Sarah', age:35}
]);
//grab names
const example = source.pluck('name');
//output: "Joe", "Sarah"
const subscribe = example.subscribe(val => console.log(val));
Example 2: Pluck nested properties

( jsBin | jsFiddle )

const source = Rx.Observable.from([
  {name: 'Joe', age: 30, job: {title: 'Developer', language: 'JavaScript'}},
  //will return undefined when no job is found
  {name: 'Sarah', age:35}
]);
//grab title property under job
const example = source.pluck('job', 'title');
//output: "Developer" , undefined
const subscribe = example.subscribe(val => console.log(val));

Additional Resources


:file_folder: Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/operator/pluck.ts

results matching ""

    No results matching ""