ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ let data = [ { name: "1", status: true, child: [ { name: "1", status: true, child: [ { name: "1", status: true, child: [ { name: "1", status: false, }, { name: "2", status: false, }, ], }, { name: "1", status: true, }, ], } ] } ] function formatArr(arr) { return arr.map((item) => { if (item.child && item.child.length > 0) { let newItem = formatArr(item.child); let status = item.status; if (newItem.every((v) => v.status == false)) { status = false; } else { status = true; } return { ...item, status, child: newItem, }; } return item; }); } console.log(JSON.stringify(formatArr(data))); ~~~