for...in Statements

for...in statements iterate specific variables over all properties of an object. For each property, JavaScript executes the specified statements.

for...in statements syntax:

for (variable in object) {
  statements }

Example—An object and its name used as the argument, iteration over all properties of the object, and return of a string that lists property names and values:

function dump_props(obj, obj_name) {
   var result = ""
   for (var i in obj) {
      result += obj_name + "." + i + " = " + obj[i] + ""
   }
   result += "<HR>"
   return result
}

Example—Car (as the object) with properties make and model:

car.make = Ford
car.model = Mustang