A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/javascript/statements/for_in below:

for in · WebPlatform Docs

for in Summary

Executes one or more statements for each property of an object, or each element of an array.

Syntax
for ( variable in [ object | array ]) {
    statements
}
variable
Required. A variable that can be any property name of object or any element index of an array.
object , array
Optional. An object or array over which to iterate.
statements
Optional. One or more statements to be executed for each property of object or each element of array. Can be a compound statement.
Examples

The following example illustrates the use of the for…in statement with an object used as an associative array.


 a = {"a" : "Athens" , "b" : "Belgrade", "c" : "Cairo"}

 
 var s = ""
 for (var key in a) {
     s += key + ": " + a[key];
     s += "<br />";
 }
 document.write (s);

 
 
 
 

This example illustrates the use of the for … in statement to iterate though an Array object that has expando properties.


 var arr = new Array("zero","one","two");

 
 arr["orange"] = "fruit";
 arr["carrot"] = "vegetable";

 
 var s = "";
 for (var key in arr) {
     s += key + ": " + arr[key];
     s += "<br />";
 }

 document.write (s);

 
 
 
 
 
 
Remarks

At the beginning of each iteration of a loop, the value of variable is the next property name of object or the next element index of array. You can then use variable in any of the statements inside the loop to reference the property of object or the element of array.

The properties of an object are not assigned in a determinate manner. You cannot specify a particular property by its index, only by the name of the property.

Iterating through an array is performed in element order, that is, 0, 1, 2.

Notes

Use the Enumerator object to iterate over the members of a collection.

See also Other articles Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4