Created
December 12, 2016 07:02
-
-
Save thejsj/0b19934017c7b61fe74ac89b2847cc33 to your computer and use it in GitHub Desktop.
Javascript Cloning for Arrays
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
var a = [1, 2, 3] | |
var b = a // b now points to the same array as a | |
a === b // true | |
var c = [...a] // Makes a shallow copy of the array | |
c === a // false | |
a.push(4) | |
b // [1, 2, 3, 4] | |
c // [1, 2, 3] | |
a = null | |
b // [1, 2, 3, 4] Still point to the same array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment