function testJS() {
alert("testJS!");
testFun();
}
function testFun() {
var array = [];
var a1 = {"id":1,"num":5};
var a2 = {"id":2,"num":5};
var a3 = {"id":3,"num":10};
var a4 = {"id":4,"num":15};
var a5 = {"id":2,"num":10};
var a6 = {"id":2,"num":35};
var a7 = {"id":4,"num":25};
var a8 = {"id":1,"num":5};
array.push(a1);
array.push(a2);
array.push(a3);
array.push(a4);
array.push(a5);
array.push(a6);
array.push(a7);
array.push(a8);
console.log("array:"+ array);
console.log("array json:" + JSON.stringify(array));
console.log("len of array:" + array.length);
console.log("如何将重复项的数值加起来,再去除重复项");
var idArray = [];
for (var i =
JS 对象数组 重复id对象 求和去重
最新推荐文章于 2024-10-10 10:27:20 发布
本文探讨如何处理包含重复id的JavaScript对象数组,通过累加相同id对象的属性值并去除重复项,实现数据去重和聚合。
摘要由CSDN通过智能技术生成