---
title: "JavaScript For-in Loop"  
description: "JavaScript For-in Loop"  
author: "Danish Khan"  
published: 2012-10-01  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/1031/javascript-for-in-loop  
category: "javascript"  
tags: ["javascript"]  
reading_time: 2 minutes  

---

# JavaScript For-in Loop

[Introduction](https://yourviews.mindstick.com/view/85450/mesopotamia-introduction-to-an-ancient-civilization):\

I am going to explain you the [functionality](https://www.mindstick.com/blog/136/using-watermark-functionality-in-textbox-by-jquery) 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](https://answers.mindstick.com/qa/38482/name-the-world-s-lightest-material-which-was-manufactured-by-isro-scientists-at-the-vikram-sarabhai-space-centre-thiruvananthapuram-and-is-also-known-as-blue-air) For-in Loop. It is used to loop through [properties](https://yourviews.mindstick.com/view/81845/now-it-s-possible-to-predict-properties-of-any-molecule) 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}
```

##### Example:

```
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head><body>    <script type="text/javascript"><!--        var WinProperty;        document.write("Window Object Properties Names<br /> ");        for (WinProperty in window) {            document.write(WinProperty);            document.write("<br />");

        }        document.write("Exiting from the loop!");-->
    </script></body></html>
```

It list out various properties of [Window object](https://www.mindstick.com/forum/161284/what-are-the-key-properties-of-the-javascript-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](https://www.mindstick.com/blog/11493/what-is-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

##### Output:

![java script for loop](https://www.mindstick.com/mindstickarticle/3f7e942c-0b65-493e-901f-75d58a197327/images/d1401d36-da62-4963-8edb-d136315c1202.png)

##### Conclusion:

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

\

---

Original Source: https://www.mindstick.com/articles/1031/javascript-for-in-loop

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
