1 const data = [{ 2 name: "撤回", 3 type: "withdraw" 4 }, { 5 name: "...", 6 type: "other", 7 children: [{ 8 name: "会签", 9 type: "sign" 10 }] 11 }]; 12 13 const flat = data.reduce((pre, cur) => { 14 return cur.children ? pre.concat(cur.children) : pre.concat(cur); 15 }, []);
打印结果
[ { name: '撤回', type: 'withdraw' },
{ name: '会签', type: 'sign' } ]