function getTreeDeep(data) {
let arr = [];
arr.push(data);
let depth = 0;
while (arr.length > 0) {
let temp = [];
for (let i = 0; i < arr.length; i++) {
temp.push(arr[i]);
}
arr = [];
for (let i = 0; i < temp.length; i++) {
if (temp[i].children && temp[i].children.length > 0) {
for (let j = 0; j < temp[i].children.length; j++) {
arr.push(temp[i].children[j]);
}
}
}
if (arr.length >= 0) {
depth++;
}
}
return depth;
}
var treeData = {
id: 1,
label: 1,
children: [
{
id: 2,
lable: 2
},
{
id: 3,
label: 3,
children: [
{
id: 4,
label: 4
},
{
id: 5,
label: 5
}
]
}
]
}
var deep = getTreeDeep(treeData)
console.log(deep);