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