---
title: "\"For in\" loop in JavaScript"  
description: "\"For in\" loop in JavaScript"  
author: "Anonymous User"  
published: 2021-07-19  
updated: 2021-07-19  
canonical: https://www.mindstick.com/forum/156520/for-in-loop-in-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# "For in" loop in JavaScript

How does “for in” loop work in [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)?

## Replies

### Reply by Ethan Karla

The for..in statement are just same as the foreach loop in PHP if you know. And if you don't know no worry, here you'll understand that.

for...in loops are the iterations which is used basically for executing the whole array from 0th to nth index. If you want to execute an array from 0 to last index then for...in loop will be the best prospective to achieve this.

Let's understand it with the help of an example :

```
<!DOCTYPE html>
<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
    <meta charset='utf-8' />
    <title>Switch Case Statement</title>
    <script>
        const object = { a: 1, b: 2, c: 3 };
        for (const property in object) {
            console.log(`${property}: ${object[property]}`);
        }
    </script>
</head>
<body align='center'>
</body>
</html>
```

Hope this information has cleared your confusion.

Happy Coding!

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