Javascript For In Loop Control

The Javascript for in statement iterates over the enumerable properties of an object, in arbitrary order. For each distinct property, statements can be executed. In each iteration one property from object is assigned to variable and this loop continues till the end of the object.

Syntax

<script type="text/javascript">
for (variable in object) 
{
  block to execute 
}
</script>

Javascript For In Loop Control Example

<!DOCTYPE html>
<html>  
<head>  <!-- www.techstrikers.com -->
<title>My first Javascript code</title>   
</head>  
<body bgcolor="#bnde45">
<fieldset>
<legend>Javascript For In Loop</legend>
<script> 
var obj = {a:1, b:2, c:3}; 
for (var prop in obj) {
  document.write(prop + " = " + obj[prop]);
}
</script>
</fieldset>
</body>  
</html>