[Contents] [Previous] [Next] [Index]

for...in

Iterates a specified variable over all the properties of an object. For each distinct property, JavaScript executes the specified statements.

Implemented in

Navigator 2.0, LiveWire 1.0

Syntax

for (variable in object) {
   statements}

Arguments

variable
Variable to iterate over every property.

object
Object for which the properties are iterated.

statements
Specifies the statements to execute for each property.

Examples

The following function takes as its argument an object and the object's name. It then iterates over all the object's properties and returns a string that lists the property names and their values.

function dump_props(obj, objName) {
   var result = ""
   for (var i in obj) {
      result += objName + "." + i + " = " + obj[i] + "<BR>"
   }
   result += "<HR><div align="center"> <script type="text/javascript"><!-- google_ad_client = "pub-9701331956559438"; /* 728x90, tc-big(banner) 6/4/08 */ google_ad_slot = "6771681519"; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div>"
   return result
}


[Contents] [Previous] [Next] [Index]

Last Updated: 10/31/97 12:29:59


Copyright ?1997 Netscape Communications Corporation