Skip to content

Instantly share code, notes, and snippets.

@bjdixon
Last active May 31, 2017 07:33
Show Gist options
  • Save bjdixon/8e5eb9de04074a11f08c9e1af1e14aec to your computer and use it in GitHub Desktop.
Save bjdixon/8e5eb9de04074a11f08c9e1af1e14aec to your computer and use it in GitHub Desktop.
create a new object extracting only desired properties from a source object. eg pick(['name', 'age'], {name: 'hi', age: 42, alive: true}) == {name: 'hi', age: 42}
const pick = (props, obj) => props.reduce((acc, curr) => ({ ...acc, ...{[curr]: obj[curr]} }), {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment