SOURCE

const groupBy = objectArray => objectArray.reduce((totalArr, current) => totalArr.concat(Array.isArray(current.children) ? groupBy(current.children) : current), []);

const arr = [
    {
        a: '1',
        children: [
            {
                a1: '1-1',
            }
        ]
    }, {
        b: '2',
        children: [
            {
                b1: '2-1',
            }, {
                b2: '2-2',
            }
        ],
    },
    {
        c: '3'
    }
];

console.log(groupBy(arr));
console 命令行工具 X clear

                    
>
console