Return to Snippet

Revision: 9865
at November 26, 2008 15:24 by melvitax


Initial Code
function print_r(theObj){
  if(theObj.constructor == Array ||
     theObj.constructor == Object){
    document.write("<ul>")
    for(var p in theObj){
      if(theObj[p].constructor == Array||
         theObj[p].constructor == Object){
document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
        document.write("<ul>")
        print_r(theObj[p]);
        document.write("</ul>")
      } else {
document.write("<li>["+p+"] => "+theObj[p]+"</li>");
      }
    }
    document.write("</ul>")
  }
}

print_r(prods);

Initial URL
http://www.brandnewbox.co.uk/articles/details/a_print_r_equivalent_for_javascript/

Initial Description
by andrew weaver

Initial Title
print_r  for Javascript

Initial Tags
javascript

Initial Language
JavaScript