for…in statement to loop through the javascript object properties is used to iterate through the properties in our javascript objects.

The syntax

for (variable in object) {
    //do something with the variable


"use strict"

var obj = {a:1, b:2, c:3};
for (var prop in obj) {
 console.log("obj." + prop + " = " + obj[prop]);

// Output:
// "obj.a = 1"
// "obj.b = 2"
// "obj.c = 3"

You may also use the without using the var keyword if you do no have “use strict” at the top.

1 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
0 Comment authors
Different ways of setting a value to a Javascript object – Muthukrishnan Recent comment authors
newest oldest most voted
Notify of

[…] be looped”. This property is used to restrict the set property to show up when using the for…in […]