人到中年有点甜
这需求改的和之前差的很大哦...这个答案是应之前的需求:返回所有admin,并且删除children中admin。getRoles(getData());function getRoles(data, role = 'admin') { let resArr = []; main(data); return resArr; function main(data) { if (data && data.length) { data.forEach((d, i) => { if (d.role === 'admin') resArr.push(data.splice(i, 1)); if (d.children && d.children.length) main(d.children); }); } }}function getData() { return [{ role: 'other', children: [{ role: 'admin', index: '1' }, { role: 'other' }] },{ role: 'admin', index: '2', children: [{ role: 'other', children: [{ role: 'admin', index: '3' }] }] }];}