Skip to content

Instantly share code, notes, and snippets.

@luan0ap
Created December 4, 2018 17:00
Show Gist options
  • Select an option

  • Save luan0ap/727b809fdf668a598e17d659f141c979 to your computer and use it in GitHub Desktop.

Select an option

Save luan0ap/727b809fdf668a598e17d659f141c979 to your computer and use it in GitHub Desktop.
pick a properties from object, by an array
const pick = (obj = {}) => (props = []) => {
var picked = {}
props.forEach((prop) => picked[prop] = obj[prop])
return picked
}
const lunch = {
sandwich: 'turkey',
drink: 'water',
chips: 'salt and vinegar',
desert: true
}
pick(lunch)(['drink', 'chips']) // { drink: 'water', chips: 'salt and vinegar' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment