Skip to content

Instantly share code, notes, and snippets.

@r4fx
Created January 4, 2019 10:37
Show Gist options
  • Save r4fx/3bbd9a8ce6625413458fdd7724db9cea to your computer and use it in GitHub Desktop.
Save r4fx/3bbd9a8ce6625413458fdd7724db9cea to your computer and use it in GitHub Desktop.
Copying an array
const names = [ 'Jon', 'Jacob', 'Jeff' ]
const copy1 = names.slice()
const copy2 = [].concat(names)
const copy3 = Object.values(names)
const copy4 = [...names]
const copy5 = Array.of(...names)
const copy6 = JSON.parse(JSON.stringify(names))
const copy7 = names.map(i => i)
const copy8 = Object.assign([], names)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment