Easy Tutorial
❮ Prop Style Transitiontimingfunction Prop Select Type ❯

JavaScript for/in Statement

JavaScript Statements Reference Manual

Example

Loop through object properties:

var person = {fname:"John", lname:"Doe", age:25}; 

var text = "";
var x;
for (x in person) {
    text += person[x] + " ";
}

text output result:

John Doe 25

Definition and Usage

The for/in statement loops through the properties of an object.

Each time the code block in the loop executes, it operates on an element of the array or a property of the object.

JavaScript supports different types of loops:

Note: Do not use the for/in statement to loop through array indices; you can use the for statement instead.


Browser Support

Statement
for/in Yes Yes Yes Yes Yes

Syntax

Parameter Values

Parameter Description
var Required. The specified variable can be an array element or an object property.
object Required. The object to iterate over.

Technical Details

| JavaScript Version: | 1.0 | | --- | --- |


Related Pages

JavaScript Tutorial: JavaScript For Loop

JavaScript Reference Manual: JavaScript for Statement


❮ Prop Style Transitiontimingfunction Prop Select Type ❯