Statement
Executes one or more statements that correspond to each element of an object, or an array.
for (variable in [object | array])
statements
Parameters
Variable
Required option. A variable that can be either a property of object or any element of an array .
Object, array
Options available. The object or array to traverse on.
Statement
Options available. One or more statements to be executed relative to each attribute of object or to each element of the array . Can be a compound statement .
Description
Before each iteration of the loop,variable is assigned the next attribute of object or the next element of the array . It can then be used in any statement within the loop, as if it is using the property of object or the element of the array .
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 the variable . The iteration is executed within the array in the order of the elements, that is, 0, 1, 2 、......
Example
The following example illustrates the use of the for ... in statement, which uses an object as a federated array:
Create certain variables. var a, key, s = ""; initializes the object. The a = {"a" : "Athens" , "b" : "Belgrade", "c" : "Cairo"} iteration property. for (in a) {s += a[key] + "<BR>"; } return(s);}
Requirements
Version 5
Note Use the enumerator object to iterate through the members of the collection.
Please see
For Statement | While statement