企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
``` 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)); ```