Filter keys in an array of objects
npm install get-only --save
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,
//=> }];
- collect.js - Dependency free wrapper for working with arrays and objects
MIT © Daniel Eckermann