Skip to content

Instantly share code, notes, and snippets.

@gabeno
Created August 13, 2013 10:20
Show Gist options
  • Save gabeno/6219863 to your computer and use it in GitHub Desktop.
Save gabeno/6219863 to your computer and use it in GitHub Desktop.
Code snippet for blog entry: Array Index versus Object Property Name
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