Last active
December 20, 2021 13:52
-
-
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
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', | |
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