The for/in a loop is usually used to loop through the properties of an object. You can give any name for the variable, but the object’s name should be the same as an already existing object you need to loop through.

Syntax:

for (variablename in objectname)

{

lines of code to be executed

}

Example:

<html>
<head>
    <script type="text/javascript">
        var employee={first:"John", last:"Doe", department:"Accounts"};
		var		details = "";
		document.write("<b>Using for/in loops </b><br />");
        for (var x in employee)
        {
		details = x + ": " + employee[x];
		document.write(details + "<br />");
        }
    </script>
</head>
<body>
</body>
</html>