Javascript for…in loop

Javascript for loop is used to do a set of operations many times. At the same time for…in is used to loops through properties of an object

SYNTAX:

for (variable in object)
{
//statements

}

EXAMPLE:

<html>
<body>
<script type="text/javascript">
var student={name:"XXX",rollno:01,marks:92.5};
var x;
for (x in student)
{
document.write(student[x] + " ");
}
</script>
</body>
</html>

OUTPUT:

XXX 1 92.5

Posted in Javascript Tagged with: