[{a:1000,b: 10},{a:1000,b:11},{a:10001,b:10}]
把数组对象里面的a属性值相同的b属性累加
得到这样的结果:
[{a:1000,b:21},{a:10001,b:10}]
obj_merge(obj){
var obj1 = {};
if(Object.prototype.toString.call(obj) != '[object Array]'){
return obj;
}
var obj2 = new Array();
obj.map(function(x){
var temp =x.a;
if(temp in obj1){
var sum = obj1[temp].b*1+x.b*1;
obj1[temp]={a:temp,b:sum}
}else{
obj1[temp]={a:temp,b:x.b}
}
})
for(i in obj1){
obj2.push(obj1[i]);
}
return obj2;
}