💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
``` 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)); ```