SOURCE

const tree = {
    label: '1',
    children: [
        {
            label: '测试节点1',
            children: [
                {
                    label: '222',
                },
                {
                    label:'333'
                }
            ]
        },
        {
            label: '测试节点2',
            children: [

                {
                    label: '5333',
                    children: [
                        {
                            label: '2333'
                        },
                        {
                            label: '33'
                        }
                    ]
                },
                {
                    label: '1333'
                },
            ]
        },
         {
            label: '测试节点3',
            children: [
                {
                    label: '534333'
                },
                {
                    label: '13533'
                },
            ]
        }
    ]
}
function search(node) {
    if (node.children) {
        node.children = node.children.filter(c => {
            if (c.children) {
                search(c)
            }
            return c.children && c.children.length > 0 || c.label.includes('333');
        })
    }
    // if(node.children.length)
}
search(tree)
console.log(tree)
console 命令行工具 X clear

                    
>
console