Find leaf nodes in tree
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" }]; Copy
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" }];
the root node of the tree, can be a single node or an array of nodes
the child key name of the child node in the tree structure,default value is CHILDREN_NAME='children'
node | null
Generated using TypeDoc
Find leaf nodes in tree
Example