🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
``` let arry=[ {Code:'x',Quantity:1,ItemType:'normal'}, {Code:'x',Quantity:2,ItemType:'normal'}, {Code:'x',Quantity:5,ItemType:'normal'}, {Code:'y',Quantity:1,ItemType:'spec'}, {Code:'y',Quantity:2,ItemType:'spec'}, {Code:'z',Quantity:1,ItemType:'normal'}, ] let newfood=[]; var temp = {}; for(var i in arry) { var key= arry[i].Code; if(temp[key]) { temp[key].Code = temp[key].Code ; temp[key].Quantity = temp[key].Quantity+ arry[i].Quantity; } else { temp[key] = {}; temp[key].Code = arry[i].Code; temp[key].Quantity = arry[i].Quantity; } temp[key].ItemType= arry[i].ItemType; } for(var k in temp){ newfood.push(temp[k]) } alert(JSON.stringify(newfood)); ```