Skip to content

Instantly share code, notes, and snippets.

@stefanocudini
Created March 25, 2012 13:01
Show Gist options
  • Select an option

  • Save stefanocudini/2193532 to your computer and use it in GitHub Desktop.

Select an option

Save stefanocudini/2193532 to your computer and use it in GitHub Desktop.
print_r() in javascript
function print_r(theObj) {
var out = '';
if(theObj.constructor == Array ||
theObj.constructor == Object){
out +="<ul>";
for(var p in theObj){
if(theObj[p].constructor == Array||
theObj[p].constructor == Object){
out +="<li>["+p+"] => "+typeof(theObj)+"</li>";
out +="<ul>";
out +=print_r(theObj[p]);
out +="</ul>";
} else {
out +="<li>["+p+"] => "+theObj[p]+"</li>";
}
}
out +="</ul>";
}
return out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment