Skip to content

Instantly share code, notes, and snippets.

@lenivene
Last active September 16, 2019 14:02
Show Gist options
  • Save lenivene/4ee7b24936e5cd4d09cebfc8fae1e4a5 to your computer and use it in GitHub Desktop.
Save lenivene/4ee7b24936e5cd4d09cebfc8fae1e4a5 to your computer and use it in GitHub Desktop.
A simple pluck function.

EXAMPLE

const Pluck = require('./Pluck');

// Exaple
const params = {
  name     : 'Lenivene Bezerra',
  email    : '[email protected]',
  username : 'lenivene'
}

const plucked = Pluck( params, 'name', 'email' );

// This result
// { name : 'Lenivene Bezerra', email : 'lenivene@soufleet.com' }
console.log("Plucked", plucked);
module.exports = (object, ...keys) => {
const newObject = {};
keys.forEach(key => newObject[key] = object[key])
return newObject;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment