Skip to content

Instantly share code, notes, and snippets.

@Shaun2D2
Created January 26, 2019 06:10
Show Gist options
  • Save Shaun2D2/a01e9aa847bd314a6179283b80375dd9 to your computer and use it in GitHub Desktop.
Save Shaun2D2/a01e9aa847bd314a6179283b80375dd9 to your computer and use it in GitHub Desktop.
filter object keys and recombine to object
const things = { name: 'john', age: 7, crap: true };
const stuff = ['name', 'age'];
const result = Object.entries(things).filter(([index, value]) => stuff.includes(index));
const composed = result.reduce((acc, entry) => ({ [entry[0]]: entry[1], ...acc }), {})
console.log(composed);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment