Created
June 28, 2009 01:15
-
-
Save rcrowley/137178 to your computer and use it in GitHub Desktop.
print_r but for JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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