JavaScript - Object failing -
this main problem:
var obj = { "22": false, "32": true, } console.log(obj.32) //<---- not working??!?!?!
why can't reach part of object??
i know can't begin variables numbers can object parts, how can read this?
just use:
console.log(obj["32"]);
demo: http://jsfiddle.net/wrzbv/1/
or obj[32]
- 32
converted string , found same using "32"
.
there 2 ways access object property name - bracket notation (what suggested) , dot notation (what you're using). dot notation, must use valid identifier, 32
not...just can't var 32 = "whatever";
reference:
Comments
Post a Comment