Created
July 18, 2012 05:26
-
-
Save jamiel/3134380 to your computer and use it in GitHub Desktop.
Yet another javascript gotcha
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
Auto-filling Array Keys | |
======================= | |
var foo = new Array(); | |
foo[500] = 'bar'; | |
console.log(foo.length); // 501 | |
// And it gets worse: | |
var foo = new Array(); | |
foo["500"] = 'bar'; | |
console.log(foo.length); // 501 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment