Posted By

melvitax on 11/26/08


Tagged

javascript printr


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ginoplusio
indamix


print_r for Javascript


 / Published in: JavaScript
 

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

by andrew weaver

  1. function print_r(theObj){
  2. if(theObj.constructor == Array ||
  3. theObj.constructor == Object){
  4. document.write("<ul>")
  5. for(var p in theObj){
  6. if(theObj[p].constructor == Array||
  7. theObj[p].constructor == Object){
  8. document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
  9. document.write("<ul>")
  10. print_r(theObj[p]);
  11. document.write("</ul>")
  12. } else {
  13. document.write("<li>["+p+"] => "+theObj[p]+"</li>");
  14. }
  15. }
  16. document.write("</ul>")
  17. }
  18. }
  19.  
  20. print_r(prods);

Report this snippet  

You need to login to post a comment.