/get-only

Filter keys in an array of objects

Primary LanguageJavaScriptMIT LicenseMIT

get-only

Filter keys in an array of objects

travis npm version npm downloads npm license prs Welcome eslint

Installation

npm install get-only --save

Usage

const only = require('get-only');

const players = [{
  firstname: 'Sadio',
  lastname: 'Mané',
  number: 19,
}, {
  firstname: 'Mohamed',
  lastname: 'Salah',
  number: 11,
}, {
  firstname: 'Roberto',
  lastname: 'Firmino',
  number: 9,
}];

only(players, ['lastname', 'number']);

//=> [{
//=>   lastname: 'Mané',
//=>   number: 19,
//=> }, {
//=>   lastname: 'Salah',
//=>   number: 11,
//=> }, {
//=>   lastname: 'Firmino',
//=>   number: 9,
//=> }];

Related

  • collect.js - Dependency free wrapper for working with arrays and objects

License

MIT © Daniel Eckermann