Skip to content

Instantly share code, notes, and snippets.

@oleksapro
Created May 17, 2018 21:55
Show Gist options
  • Save oleksapro/6955c066780b916891c293e409306c96 to your computer and use it in GitHub Desktop.
Save oleksapro/6955c066780b916891c293e409306c96 to your computer and use it in GitHub Desktop.

https://www.briangonzalez.org/post/copying-array-javascript

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