For In Statement
The For In statement loops through the properties of an associative array or object. You cannot use it with a nonassociative array. For more information, see About Associative Arrays.
You cannot write code that references a property that is marked with the DONT_ENUM attribute in a For In statement. The DONT_ENUM attribute is a predefined attribute that you cannot modify.
Format
for (LoopVar in object)
{
statement_block;
}
The following table describes the arguments for the For In statement. The statement block runs one time for every element in the associative array or property of the object.
Argument | Description |
---|---|
object |
An associative array or object:
|
LoopVar |
A variable that iterates over every element that resides in the associative array or property of the object. For each iteration of the loop, the LoopVar argument identifies the name of a property of the object or an element of the array. You can write code that references it with a statement that uses the following format:
|
Example
The following example creates an object named obj, and then uses the For In statement to read the object properties:
function PropBtn_Click ()
{
var obj = new Object;
var propName;
var msgtext = "";
obj.number = 32767;
obj.string = "Welcome to my world";
obj.date = "April 25, 1945";
for (propName in obj)
{
msgtext = msgtext + "The value of obj." + propName +
" is " + obj[propName] + ".\n";
}
TheApplication().RaiseErrorText(msgtext);
}
Running this code produces the following results:
The value of obj.number is 32767.
The value of obj.string is Welcome to my world.
The value of obj.date is April 25, 1945.
For an example of the For In statement used with an associative array, see About Associative Arrays.