[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>"
   return result
}


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

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


Copyright © 1997 Netscape Communications Corporation