How to recursively generate a list of ul?

Need of n dimensional array to generate a ul list, I've poked this code but the process has stalled - maybe someone with fresh eyes to tell how to do?

In fact the structure as follows:
[
{
 "id": 1,
 "parent_id": null,
 "children": [
{
 "id": 2,
 "parent_id": 1,
 "children": []
},
{
 "id": 3,
 "parent_id": 1,
 "children": [
{
 "id": 4,
 "parent_id": 3,
 "children": []
}
]
}
]
}
]

I want to generate at the output of this html'ku:
<ul id="organisation">
<li>1
the <ul>
the <li>2</li>
the <li>3
the <ul>
the <li>4</li>
</ul>
</li>
</ul>
</li>
 </ul>
April 4th 20 at 13:11
1 answer
April 4th 20 at 13:13
Solution
var arr1 = [{
 "id": 1,
 "parent_id": null,
 "children": [{
 "id": 2,
 "parent_id": 1,
 "children": []
},
{
 "id": 3,
 "parent_id": 1,
 "children": [{
 "id": 4,
 "parent_id": 3,
 "children": []
}]
}
]
}];

recBuild(document.querySelector("#organisation"),arr1);

function recBuild(parentUl,arr){
arr.forEach((el)=>{
 var li = document.createElement("li");
 li.innerHTML = el.id;
 if(el.children.length > 0 ){ 
 var ul = document.createElement("ul");
recBuild(ul,el.children);
li.append(ul);
}
 parentUl.appendChild(li); 
});
}

<ul id="organisation"></ul>
Thank you very much! - greta.Oberbrunner commented on April 4th 20 at 13:16

Find more questions by tags JavaScriptRecursion