HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Iterate (loop) over the properties of an object
The for...in
statements combo iterates (loops) over the properties of an object.
The code block inside the loop is executed once for each property.
Do not use for...in to iterate an array if the index order is important. Use a for loop instead.
Parameter | Description |
x | Required. A variable to iterate over the properties. |
object | Required. The object to be iterated |
Statement | Description | |
break | Breaks out of a loop | |
continue | Skips a value in a loop | |
while | Loops a code block while a condition is true | |
do...while | Loops a code block once, and then while a condition is true | |
for | Loops a code block while a condition is true | |
for...of | Loops the values of any iterable | |
for...in | Loops the properties of an object |
Iterate over the properties of window.location:
let text = "";
for (let x in location) {
text += x + "
";
}
document.getElementById("demo").innerHTML = text;
for...in
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |