Created
June 24, 2015 09:16
-
-
Save pbakondy/6f6da994bc0e65d0db5e to your computer and use it in GitHub Desktop.
How to empty 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
var foo = [1, 2, 3]; | |
var bar = [1, 2, 3]; | |
var foo2 = foo; | |
var bar2 = bar; | |
// assigns a reference to a new array to a variable, while any other references are unaffected | |
foo = []; | |
// deletes everything in the array, which does hit other references | |
bar.length = 0; | |
console.log(foo, bar, foo2, bar2); | |
// [] [] [1, 2, 3] [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment