我有一组像这样的对象:0: {Id: "D", Inmueble: "00000021", Valexcep: 2}1: {Id: "D", Inmueble: "00000021", Valexcep: 2}2: {Id: "D", Inmueble: "00000023", Valexcep: 1}3: {Id: "D", Inmueble: "00000023", Valexcep: 2}4: {Id: "D", Inmueble: "00000024", Valexcep: 3}5: {Id: "D", Inmueble: "00000168", Valexcep: 3}我需要对那些具有相同“Inmueble”值的对象的“Valexcep”值求和,例如数组的前两个我需要能够得到这个输出0: {Id: "D", Inmueble: "00000021", Valexcep: 4}2: {Id: "D", Inmueble: "00000023", Valexcep: 3}4: {Id: "D", Inmueble: "00000024", Valexcep: 3}5: {Id: "D", Inmueble: "00000168", Valexcep: 3}这是我到目前为止的代码 var discount = 0; var inmueble = ""; $.each(array, function(i, val) { if (val.Id == 'D') { discount += val.Valexcep; inmueble = val.Inmueble; var newObj = { id: val.Id, Inmueble: val.Inmueble Valexcep: val.Valexcep; } array.push(newObj) } });但没有按预期工作,知道如何解决这个问题吗?
添加回答
举报
0/150
提交
取消