The for-in statement is used to return a property or properties of an object.

The syntax looks like this:

for (property in expression) {

   statement;

}

Or in the real example with real values:

var prop;

var person={firstname:"John",lastname:"Doe",age:105};

for (prop in person) {

   alert(person[prop];

}

Therefore, the variable prop will represent one property of the person object in each loop. The next loop call will shift the pointer to the next property in the object, till all of them are enumerated.

Example

The example with for-in statement in JavaScript:

 

›› go to examples ››