The for/in Statement

Navigation Aids -- This Page           Navigation Aids -- This Topic           Navigation Aids -- This Site

Review of Terms Related to This Topic

Definition and Purpose

The for/in statement is another one of JavaScript's program control statements. The for/in statement provides the means to loop through the properties of an object. The loop body statements are executed once for each property of the object. The loop control mechanism is implicitly controlled, unlike the for statement where the loop control mechanism is explicitly expressed.

It is not possible to control the order of the properties assigned to the identifier. Therefore, the order can vary between implementations. The for/in statement may be used to loop through the elements of an array. Here, the order will be consistent (from element 0 to element n).

Statement Syntax

for (identifier in object) {    loop body statement or block }

More on Syntax and Statement Behavior

for/in Statements and Block Statements

The loop body is contained within curly braces. This is a use of the block statement. The for/in statement is just one example of where the block statement may be used.

ECMA-262 Section 12.6.4

The for/in statement is an ECMAScript core statement and is detailed is section 12.6.4 of the ECMAScript Language Specification. Here is a partial extraction of text from this section.

Iteration Statements: An iteration statement consists of a header (which consists of a keyword and a parenthesized control construct) and a body (which consists of one of more statements).


Rx4AJAX        About Us | Topic Index | Contact Us | Privacy Policy | 2008 This Site Built By PPThompson