例:
let arr = [ { situationId: '666666666666666666666', cloundClass: '999', }, { situationId: '1608655741214162944', cloundClass: '123', }, { situationId: '1608655741214162944', cloundClass: '456', }, { situationId: '1608655741214162944', cloundClass: '789', }, { situationId: '1608655741214162944', cloundClass: '000', }, { situationId: '666666666666666666666', cloundClass: '999', }, ] 处理方法: let bb = arr.reduce((obj, item) => { let find = obj.find((i) => i.situationId === item.situationId); let ss = { situationId: item.situationId, cloundClass: [item.cloundClass] }; find ? find.cloundClass.push(item.cloundClass) : obj.push(ss); return obj; }, []); 标签:situationId,reduce,find,item,let,数组,obj,id,cloundClass From: https://www.cnblogs.com/zj6666/p/17057606.html