javascript for in loop tutorial

The for in loop is used to iterate the properties of an object.

Syntax:

for(property in object){
 //Block of statements 
}

:

<html>
<head>
<script>  
var person = {Fname:"Mahesh", Lname:"Kumawat", Age:29};
var perproperty;
for (perproperty in person) {
document.write(perproperty + ": " + 
person[perproperty ] + "<br/>")  
}  
</script> 
</head>
<body> 
</body>
</html>

Output:

Fname: Mahesh
Lname: Kumawat
Age: 29