/ Published in: JavaScript

The code below will loop through the properties in an object and alert a string. myObject is in JSON notation. The "for ( x in y)" construct does not work if the Prototype.js library is included on the page
Expand |
Embed | Plain Text
// output the name and value of all the objects properties var s = ""; for (var property in myObject) { s = s + "\n "+property +": " + myObject[property] ; } alert(s);
Comments

You need to login to post a comment.
Nice snippet! This page also had a few other ways to print out a javascript object as well:
how to print a Javascript object