• Find leaf nodes in tree

    Example

    import { findLeafNodes } from "tree-handle-lib";

    const node = {
    key: "node1",
    children: [
    {
    key: "node2",
    children: [{ key: "leaf1" }, { key: "leaf2" }],
    },
    {
    key: "node3",
    children: [{ key: "leaf3" }, { key: "leaf4" }],
    },
    ],
    };
    const result = findLeafNodes(node);

    // console.log(JSON.stringify(result));

    [{ key: "leaf1" }, { key: "leaf2" }, { key: "leaf3" }, { key: "leaf4" }];

    Parameters

    • node: TNode

      the root node of the tree, can be a single node or an array of nodes

    • childrenName: string = CHILDREN_NAME

      the child key name of the child node in the tree structure,default value is CHILDREN_NAME='children'

    Returns TTreeNode[]

    node | null

Generated using TypeDoc