Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Last active September 21, 2019 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NyaGarcia/b65a2d59a7f750421f1812a671eaf5d7 to your computer and use it in GitHub Desktop.
Save NyaGarcia/b65a2d59a7f750421f1812a671eaf5d7 to your computer and use it in GitHub Desktop.
Dynamically destructuring an array of properties with the spread operator
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