function removeDuplicatesWithCondition(arr) {
const seen = new Map(); const result = []; arr.forEach(item => { if (item.cid && 'condition' in item) { if (!seen.has(item.cid)) { seen.set(item.cid, item); result.push(item); } } else { result.push(item); } }); return result;}const array = [ { cid: 1, condition: true, name: "A" }, { cid: 1, condition: true, name: "B" }, { cid: 2, condition: false, name: "C" }, { cid: 2, name: "D" }, { cid: 3, name: "E" },];console.log(removeDuplicatesWithCondition(array));
【无标题】u额u额u额呜呜呜呜
于 2024-04-18 17:39:29 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)