Created
January 4, 2019 10:37
-
-
Save r4fx/3bbd9a8ce6625413458fdd7724db9cea to your computer and use it in GitHub Desktop.
Copying an array
This file contains 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