This question already has an answer here:
below is a simple samlple, i wanna display the object properties using for/in loop
var Object = { x:1, y:2, z:3 };
for (property in Object) {
console.log(Object.property);
};
it shows undefined.
but if using console.log(Object[property]);
it works, and shows 1 2 3
why i cannot use Object.property
to display in for/in loop?
Object[property]
. Second, don't use "Object" as the variable's name - it's the object constructor, and may or may not mess up other things...**especially** if this code is in the global scope – Ian Jun 11 '13 at 16:52