Last active
December 22, 2021 17:38
-
-
Save NyaGarcia/3ccd6f8fcfa27e05aec6f1f7657c537c to your computer and use it in GitHub Desktop.
Adding a default property with the spread operator
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 = { | |
name: 'Squirtle', | |
type: 'Water' | |
}; | |
const { abilities = [], ...rest } = pokemon; | |
const fullSquirtle = { ...rest, abilities }; | |
console.log(rest); //Result: { name: 'Squirtle', type: 'Water' } | |
console.log({ fullSquirtle }); //Result: { name: 'Squirtle', type: 'Water', abilities: [] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment