JavaScript: Enumerating Properties of an Object with a For/In Loop
***If this post helped you, please support this blog by clicking one of the links on this page. Thanks :) ***
JavaScript object properties can be enumerated by using a for/in loop, as demonstrated below:
var objCar = new Object();
objCar.wheels = 4;
objCar.tires = 4;
objCar.engines = 1;
for (var i in objCar)
{
document.write(i);
document.write('<br/>');
}
The result of this code is:
wheels
tires
engines