Created
September 21, 2019 15:53
-
-
Save NyaGarcia/5419b68a41909cb8bb5dd9450b648683 to your computer and use it in GitHub Desktop.
Dynamically destructuring object 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
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