var obj = {
function1: function() {},
function2: function() { return "return from function2"; },
value1: "this is value1"
}
console.log("for each in:");
/* iterate over obj property values */
for each (var value in obj) {
console.log(value);
}
/* after this in your console (eg. in firebug) should be logged these:
function(), function(), "this is value1" - notice these are objects */
console.log("for in:");
/* iterate over property names in obj*/
for (var property in obj) { /* property variable is always String */
console.log(property);
}
/* in your eg. firebug console there are logged these Strings: "function1", "function2", "value1" */
See: https://developer.mozilla.org/en/JavaScript/Reference/Statements/for_each...in
Žádné komentáře:
Okomentovat