Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created September 21, 2019 14:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NyaGarcia/456eafcc61027ce48ac9d460b673acad to your computer and use it in GitHub Desktop.
Save NyaGarcia/456eafcc61027ce48ac9d460b673acad to your computer and use it in GitHub Desktop.
Renaming object properties while destructuring them
const squirtle = { type: 'Water', ability: 'Torrent' };
//Normal property destructuring:
const { type, ability } = squirtle;
console.log({ type }, { ability }); //Result: { type: 'water' } { ability: 'torrent' }
//Renaming properties
const { type: squirtleType, ability: superAwesomeAbility } = squirtle;
console.log({ squirtleType }, { superAwesomeAbility }); //Result: { squirtleType: 'Water' } { superAwesomeAbility : 'Torrent' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment