Last active
September 21, 2019 15:39
-
-
Save NyaGarcia/b65a2d59a7f750421f1812a671eaf5d7 to your computer and use it in GitHub Desktop.
Dynamically destructuring an array of properties with the spread operator
This file contains hidden or 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
function dynamicDestructureMany(object, properties) { | |
return properties.map(property => { | |
const { [property]: value } = object; | |
return value; | |
}); | |
} | |
console.log(dynamicDestructureMany(pokemon, ['name', 'type'])); //Result: ['Squirtle', 'Water'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment