Skip to content

Instantly share code, notes, and snippets.

@soundlake
Created February 20, 2017 10:41
Show Gist options
  • Save soundlake/21980203cf448e152ef5deee866ca529 to your computer and use it in GitHub Desktop.
Save soundlake/21980203cf448e152ef5deee866ca529 to your computer and use it in GitHub Desktop.
Using jQuery, convert plain JS object to un-ordered list
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