• Remove node from tree by key

    Example

    import { removeNodeByKey } from "tree-handle-lib";
    const node = [
    {
    key: "1",
    children: [
    {
    key: "2",
    children: [
    {
    key: "3",
    children: [
    {
    key: "4",
    children: [],
    },
    ],
    },
    ],
    },
    {
    key: "5",
    children: [
    {
    key: "6",
    children: [],
    },
    ],
    },
    ],
    },
    ];
    const _result = removeNodeByKey(node, "3");
    // [
    // {
    // key: "1",
    // children: [
    // { key: "2", children: [] },
    // { key: "5", children: [{ key: "6", children: [] }] },
    // ],
    // },
    // ];

    Parameters

    • node: TNode

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

    • key: string | string[]

      the key of find the destination node

    • childrenName: string = CHILDREN_NAME

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

    • keyName: string = KEY_NAME

      the key name of the node in the tree structure,default value is KEY_NAME='key'

    Returns any

Generated using TypeDoc