Javascript Reference
Categories: Operators

javascript Operators for/in

@March 15, 2008, 1:22 a.m.
for/in Firefox/Netscape/NN 2 IE 3 ECMA 1  

  

This is a variation of the regular for loop that can extract the property names and values of an object. Only properties (and, in Netscape 6, methods) that are set to be enumerable by the browser internals appear in the output of this construction. Opera 6 supports this construction only for custom script-generated objects.

 
Example
 
function showProps( ) {
    objName = "image";
    obj = document.images[0];
    var msg = "";
    for (var i in obj) {
        msg += objName + "." + i + "=" + obj[i] + "\n";
    }
    alert(msg);
}

Powered by Linode.