Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created September 21, 2019 15:53
Show Gist options
  • Save NyaGarcia/5419b68a41909cb8bb5dd9450b648683 to your computer and use it in GitHub Desktop.
Save NyaGarcia/5419b68a41909cb8bb5dd9450b648683 to your computer and use it in GitHub Desktop.
Dynamically destructuring object properties with the spread operator
const pokemon = {
id: 1,
name: 'Squirtle',
type: 'Water'
};
//Destructuring a dynamic property
const dynamicProperty = 'name';
const { [dynamicProperty]: value } = pokemon;
console.log(value); //Result: Squirtle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment