JavaScript for in is used to loops through the properties of an object. This means a block of code inside the loop will be executed once for each property.
Syntax
The syntax of the for…in the loop is:
for (variable in object)
//statement
Example of JavaScript for…in array
HTML example code of for…in the loop through the properties of an object:
<!DOCTYPE html>
<html>
<head>
<script>
const object = { a: 1, b: 2, c: 3 };
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}
</script>
</head>
<body>
</body>
</html>
Output:
Do comment if you have another example or doubts or suggestions on this topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version