Created
February 20, 2017 10:41
-
-
Save soundlake/21980203cf448e152ef5deee866ca529 to your computer and use it in GitHub Desktop.
Using jQuery, convert plain JS object to un-ordered list
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 object_to_ul(o) { | |
var $ul = $('<ul/>'); | |
for (var k in o) { | |
var $li = $('<li/>').text(k); | |
if (o[k] !== null && typeof(o[k]) == 'object') | |
$li.append(object_to_ul(o[k])); | |
$ul.append($li); | |
} | |
return $ul; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment