Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Last active September 23, 2019 16:43
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/e9c37542f261d1ee6357a4e15fdf9ce8 to your computer and use it in GitHub Desktop.
Save NyaGarcia/e9c37542f261d1ee6357a4e15fdf9ce8 to your computer and use it in GitHub Desktop.
Showing how the existing abilities property isn't modified
const pokemon = {
name: 'Squirtle',
type: 'Water',
abilities: ['Torrent', 'Rain Dish']
};
const { abilities = [], ...rest } = pokemon;
const fullSquirtle = { ...rest, abilities };
console.log(rest); //Result: { name: 'Squirtle', type: 'Water' }
//Since the pokemon object already has the abilities property, it isn't modified:
console.log({ fullSquirtle }); //Result: { name: 'Squirtle', type: 'Water', abilities: ['Torrent', 'Rain Dish'] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment