The World Wide Web, restored to 800 pixels of glory.
GeezerVison is showing fa.javascript.info — Create a tree from the object
Write a function createTree that creates a nested ul/li list from the nested object.
createTree
ul/li
For instance:
let data = { "Fish": { "trout": {}, "salmon": {} }, "Tree": { "Huge": { "sequoia": {}, "oak": {} }, "Flowering": { "apple tree": {}, "magnolia": {} } } };
The syntax:
let container = document.getElementById('container'); createTree(container, data); // creates the tree in the container
The result (tree) should look like this:
Choose one of two ways of solving this task:
container.innerHTML
Would be great if you could do both.
P.S. The tree should not have “extra” elements like empty <ul></ul> for the leaves.
<ul></ul>
باز کردن یک sandbox برای تمرین.
The easiest way to walk the object is to use recursion.