Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. const pokemon = {
  2. useless: 'useless property',
  3. id: 1,
  4. name: 'Squirtle',
  5. type: 'Water'
  6. };
  7.  
  8. // Removing the useless property:
  9. ({ useless, ...newPokemon } = pokemon);
  10. console.log(newPokemon); // Result: { id: 1, name: 'Squirtle', type: 'Water' }
  11.  
  12. // The rest parameter MUST be placed last, this will throw an error:
  13. ({ ...otherPokemon, id, useless } = pokemon);
  14. console.log(otherPokemon); // Result: SyntaxError
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement