Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created September 21, 2019 15:40
Show Gist options
  • Save NyaGarcia/7deaec76ad8a92bc46585a51e6745060 to your computer and use it in GitHub Desktop.
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)
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