Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement