Function: treeDepth()
ts
function treeDepth<T>(trees, childrenKey?): number;Calculates the maximum depth of a tree. 计算树结构的最大深度。
Type Parameters
| Type Parameter | Description |
|---|---|
T extends Record<string, unknown> | The node type / 节点类型 |
Parameters
| Parameter | Type | Description |
|---|---|---|
trees | readonly T[] | The source tree array / 源树数组 |
childrenKey | keyof T | The children field name / 子节点字段名 |
Returns
number
The maximum tree depth / 最大树深度
Example
ts
treeDepth([{ id: 1, children: [{ id: 2 }] }])
// => 2Since
1.2.0