O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Iterating Through Object Properties

var obj = {first:"Bilbo", last:"Baggins", title:"Hobbit"}; for (var key in obj){   document.write(key + "=" + obj[key] + "&"); }

JavaScript provides an additional type of option in the for() loop. Using the in keyword, you can iterate through the values in an array or the properties in an object. The syntax is for( var name in object){LOOP_BLOCK}. The name is assigned the property name inside the LOOP_BLOCK.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required