Created
September 14, 2019 15:27
-
-
Save NyaGarcia/ebf6a35a3da02b17657cc9d25ac909c7 to your computer and use it in GitHub Desktop.
Copying an array immutably 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 = ['Squirtle', 'Bulbasur', 'Charmander']; | |
const pokedex = [...pokemon]; | |
pokedex.push('Cyndaquil'); | |
console.log(pokemon); //[ 'Squirtle', 'Bulbasur', 'Charmander' ] | |
console.log(pokedex); //[ 'Squirtle', 'Bulbasur', 'Charmander', 'Cyndaquil' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment