Home > DeveloperSection > Articles > JavaScript For-in Loop

JavaScript For-in Loop

JavaScript JavaScript 
0 Comment(s)
 2488  View(s)
Rate this:

JavaScript For-in Loop


I am going to explain you the functionality of for in loop, because for-in loop is a little more different from other loops.

In Java Script there is another loop which is known as For-in Loop. It is used to loop through properties of an object. There are various objects like Navigator objects and Window objects which I will be explaining later on. These objects contain various properties which can be easily accessed using. The example given below gives an idea about what is for-in loop and why it is used.

Syntax of for-in Loop:

for (variable in object)


         Code to be executed



<html xmlns="http://www.w3.org/1999/xhtml">




    <script type="text/javascript">


        var WinProperty;

        document.write("Window Object Properties Names<br /> ");

        for (WinProperty in window) {


            document.write("<br />");


        document.write("Exiting from the loop!");





It list out various properties of Window object. In similar way we can list of other object properties.         In each iteration one property of an object is assigned in a variable WinProperty. Till all of the property is not accessed and assigned to the variable the for-in loop will continue executing and printing the property name on the screen.

                This loop differs from the for loop, that for loop does not work on objects


java script for loop


In this article I explained the concept of for-in loop and how it works, how it differs from for loop.

Don't want to miss updates? Please click the below button!

Follow MindStick