Last active
September 23, 2019 16:43
-
-
Save NyaGarcia/e9c37542f261d1ee6357a4e15fdf9ce8 to your computer and use it in GitHub Desktop.
Showing how the existing abilities property isn't modified
This file contains 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 = { | |
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