Skip to content

Instantly share code, notes, and snippets.

@rcrowley
Created June 28, 2009 01:15
Show Gist options
  • Save rcrowley/137178 to your computer and use it in GitHub Desktop.
Save rcrowley/137178 to your computer and use it in GitHub Desktop.
print_r but for JavaScript
function obj2ul(obj) {
var ul = document.createElement('ul');
if ('object' == typeof obj) {
for (var k in obj) {
var li = document.createElement('li');
if ('object' == typeof obj[k]) {
li.appendChild(document.createTextNode(k + ':'));
li.appendChild(obj2ul(obj[k]));
} else {
li.appendChild(document.createTextNode(k + ': ' + obj[k]));
}
ul.appendChild(li);
}
return ul;
} else { return null; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment