Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Last active December 22, 2021 17:38
Show Gist options
  • Save NyaGarcia/3ccd6f8fcfa27e05aec6f1f7657c537c to your computer and use it in GitHub Desktop.
Save NyaGarcia/3ccd6f8fcfa27e05aec6f1f7657c537c to your computer and use it in GitHub Desktop.
Adding a default property with the spread operator
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