Created
January 26, 2019 06:10
-
-
Save Shaun2D2/a01e9aa847bd314a6179283b80375dd9 to your computer and use it in GitHub Desktop.
filter object keys and recombine to object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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