var tree = [
{name: 'node1'},
{name: 'node2', children:[{name: 'node-2-1'}, {name: 'node2-2'}]},
{name: 'node3', children:[{name: 'node-3-1', children:[{name: 'node3-1-1'}]}, {name: 'node3-2'}]}
];
var render = function render (tree) {
if (!tree) return null
var ul = document.createElement('ul');
tree.forEach(({name, children}) => {
var li = document.createElement('li')
var label = document.createElement('span'); label.innerText = name;
li.appendChild(label);
var sub = render(children);
sub && li.appendChild(sub);
ul.append(li);
})
return ul
};
document.body.innerHTML = '';
document.body.appendChild(render(tree));