多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
``` 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)); ```