Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created October 4, 2019 17:19
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/21f3fd578102dab1ba6adea761515f8c to your computer and use it in GitHub Desktop.
Save NyaGarcia/21f3fd578102dab1ba6adea761515f8c to your computer and use it in GitHub Desktop.
Removing object properties with the rest parameter
const pokemon = {
useless: 'useless property',
id: 1,
name: 'Squirtle',
type: 'Water'
};
// Removing the useless property:
({ useless, ...newPokemon } = pokemon);
console.log(newPokemon); // Result: { id: 1, name: 'Squirtle', type: 'Water' }
// The rest parameter MUST be placed last, this will throw an error:
({ ...otherPokemon, id, useless } = pokemon);
console.log(otherPokemon); // Result: SyntaxError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment