Microsoft® JScript™ for...in Statement | Language Reference Version 1

See Also

##### Description

> Executes a statement for each element of an object or array.

##### Syntax

> for (variable in [object | array])
> statement

> The for statement syntax has these parts:

> Part | Description
> variable | A variable that can hold any of the elements of object.
> object, array | An object or array over which to iterate.
> statement | The statement to be executed for each member of object. Can be a compound statement.

##### Remarks

> Before each iteration of a loop, variable is assigned the next element of object. You can then use it in any of the statements inside the loop exactly as if you were using the element of object.

> When iterating over an object, there is no way to determine or control the order in which the members of the object are assigned to variable.

> The following example illustrates the use of the for ... in statement:

> >     function ForStmDemo()
> >     {
> >       // Create some variables.
> >       var a, d, i, s = "";
> >       d = new ActiveXObject("Scripting.Dictionary");
> >       // Add some keys and items
> >       d.Add ("a", "Athens");
> >       d.Add ("b", "Belgrade");
> >       d.Add ("c", "Cairo");
> >       // Get the items into an array.
> >       a = (new VBArray(d.Items())).toArray();
> >       //Iterate the dictionary.
> >       for (i in a)
> >       {
> >          s += a[i] + "\n";
> >       }
> >       return(s);
> >     }

© 1998 Microsoft Corporation. All rights reserved. Terms of Use.