Created
October 4, 2019 17:19
-
-
Save NyaGarcia/21f3fd578102dab1ba6adea761515f8c to your computer and use it in GitHub Desktop.
Removing object properties with the rest parameter
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 = { | |
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