Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Last active December 20, 2021 13:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NyaGarcia/9e803ebb4d22d3da8b3efcc7e424584e to your computer and use it in GitHub Desktop.
Save NyaGarcia/9e803ebb4d22d3da8b3efcc7e424584e to your computer and use it in GitHub Desktop.
Showing an example of mutation of an array within an object cloned with spread operator
const pokemon = {
name: 'Squirtle',
type: 'Water',
abilities: ['Torrent', 'Rain Dish']
};
const squirtleClone = { ...pokemon };
pokemon.name = 'Charmander';
pokemon.abilities.push('Surf');
console.log(squirtleClone); //Result: { name: 'Squirtle', type: 'Water', abilities: [ 'Torrent', 'Rain Dish', 'Surf' ] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment