pluck

pluck values from an object path

pluck

pluck property path from arrays or an object.

component

  $ component install gjohnson/pluck

or

npm

  $ npm install pluck

Pluck from arrays.

var pluck = require('pluck');
 
var firstName = pluck('name.first');
 
var items = [
  { name: { first: 'john', last: 'doe' } }
];
 
var names = firstName(items);

Pluck from plain objects.

var pluck = require('pluck');
 
var firstName = pluck('name.first');
 
var item = {
  name: {
    first: 'john',
    last: 'doe'
  }
};
 
var name = firstName(item);

Pluck using index expressions.

var pluck = require('pluck');
 
var firstName = pluck('name[1].first');
var item = {
  name: [
    {},
    {
      first: 'john',
      last: 'doe'
    }
  ]
};
 
var name = firstName(item);

MIT