Javascript - Loop through properties in an object(for .. in)

by sunil ravulapalli /4. January 2012 22:49 /javascript /Comments (0)

Quick Tip
If you want to loop through the properties in an object you can use the for..in loop construct.

var student = { 
    name:"tom",
    age:20
}; 

for (var key in student )
{
  document.write(key + ' = ' + student[key] + '
'); }

The above code will print:
name = tom
age = 20

blog comments powered by Disqus