for…in

JavaScript 1.0+, ECMAScript 1.0+, JScript 1.0+ Nav2+, NES2+, IE 3+, Opera3+ Syntax

for(variable in object){

  code;

}

Description

The for…in object iterates a specified variable over all the properties of an object. The statements, contained in the body, are executed once for each property. The variable is a variable interated over each property in the object. code contains JavaScript statements to be executed.

Example

Listing 6.122 shows how to use the for…in object. The showProperties function takes an object type and object name as arguments. A for…in loop is then executed on the object displaying each of the object's properties and their values.

Listing 6.122 Using the for…in Object
 <html> <body> <script language = "JavaScript> ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.