Posted By

elugardo on 08/26/09


javascript object json

Versions (?)

Output the name and value of the properties in a javascript object

 / 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

  1. // output the name and value of all the objects properties
  2. var s = "";
  4. for (var property in myObject)
  5. {
  6. s = s + "\n "+property +": " + myObject[property] ;
  7. }
  9. alert(s);

Report this snippet  


RSS Icon Subscribe to comments
Posted By: jporter892 on November 30, 2012

Nice snippet! This page also had a few other ways to print out a javascript object as well:

how to print a Javascript object

You need to login to post a comment.