Created
August 13, 2013 10:20
-
-
Save gabeno/6219863 to your computer and use it in GitHub Desktop.
Code snippet for blog entry: Array Index versus Object Property Name
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 = []; | |
a['0'] = 1; // assign value using property name as string | |
// number converted to string and used as property name | |
a[1] = 2; // assign value using property as an integer | |
a[2.0] = 3; // assign value using property as a floating point number | |
console.log(a) // => [1,2,3] | |
console.log(a.length) // => 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment