I have list of items: "Electronic" It has a category, and that category has a subcategory. How to display it properly like tree/traverse:
Example
Example
Example
Example
Example 2
Example 2
Example 2
My Code:
function getData(categories) {
categories.forEach((el) => {
console.log(el);
let uls = document.createElement('ul')
let lists = document.createElement('li')
lists.innerHTML = el.name
lists.style.listStyle = 'none'
uls.append(lists)
boxes.append(uls)
if(el.hasOwnProperty('categories') && el.categories.length > 0) {
getData(el.categories, iter)
}
})
}
getData(categories)