SOURCE

function treeToArr(tree, key) {
    let arr = []
    

    const fn =  (tree) => {
        tree.forEach(i => {        
            arr.push(i)
            if (i[key] && i[key].length > 0) {
                fn(i[key])
            }
        })
    }

    fn(tree)
    return arr
}

var b = [
    {
        name: '张三',
        chiledren: [
            {
                name: '张三1'
            },
            {
                name: '张三2'
            }
        ]
    }, {
        name: '李四',
        chiledren: [
            {
                name: "李四1"
            },
            {
                name: '李四2'
            }, {
                name: '李四3'
            }
        ]
    }, {
        name: '王五'
    }
]

var c = treeToArr(b, 'chiledren')

console.log(c)
console 命令行工具 X clear

                    
>
console