Created
May 17, 2018 11:44
-
-
Save w-jerome/900a8ab2e326c9ed042512dfad48a196 to your computer and use it in GitHub Desktop.
JavaScript — Copying an array
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 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