JSFiddle - React, Tailwind, and code Playground
JavaScript
function printTree(people, slug) {
for (var p = 0; p < people.length; p++) {
var root = people[p];
slug = slug + root.name + "/";
console.log(slug);
if (root.children.length > 0) {
var childrenCount = root.children.length;
for (var c = 0; c < childrenCount; c++) {
if (root.children[c].children.length > 0) {
printTree(root.children[c].children, slug + root.children[c].name + "/");
}
}
}
}
};
var data = [
{
"name": "michael",
"children": [
{
"name": "angela",
"children": [
{
"name": "oscar",
"children": []
}
]
},
{
"name": "meredith",
"children": [
{
"name": "creed",
"children": []
},
{
"name": "kelly",
"children": []
}
]
}
]
}
];
printTree(data, '/');