Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Created April 18, 2018 09:27
Show Gist options
  • Save gladchinda/d96b37be6d8d60c7699a655cd12de707 to your computer and use it in GitHub Desktop.
Save gladchinda/d96b37be6d8d60c7699a655cd12de707 to your computer and use it in GitHub Desktop.
const rainbow = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
// Cloning with Array.prototype.slice
const rainbowClone1 = rainbow.slice();
console.log(rainbow === rainbowClone1); // false
console.log(rainbowClone1); // ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
// Cloning with Array.prototype.concat
const rainbowClone2 = rainbow.concat();
console.log(rainbow === rainbowClone2); // false
console.log(rainbowClone2); // ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment