Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created September 14, 2019 15:27
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/ebf6a35a3da02b17657cc9d25ac909c7 to your computer and use it in GitHub Desktop.
Save NyaGarcia/ebf6a35a3da02b17657cc9d25ac909c7 to your computer and use it in GitHub Desktop.
Copying an array immutably with the spread operator
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