vardata={"67407685":{"24888861":200,"23675650":300},"24888861":{"23675650":789,"23127112":400},"23675650":{"24888861":789,"67407685":900},"23127112":{"5388329":340,"24888861":123},"38121665":{"24888861":400,"23675650":123},"5388329":{"24888861":789,"23127112":400}}我尝试循环,再循环,然后就懵了,求指点思路感激不尽
2 回答
暮色呼如
TA贡献1853条经验 获得超9个赞
我也不知道你要怎么相加。反正我是把data的每个属性的值分别相加了。vardata={"67407685":{"24888861":200,"23675650":300},"24888861":{"23675650":789,"23127112":400},"23675650":{"24888861":789,"67407685":900},"23127112":{"5388329":340,"24888861":123},"38121665":{"24888861":400,"23675650":123},"5388329":{"24888861":789,"23127112":400}};varadd=function(root_obj){for(letsecond_objinroot_obj){letsum=0;for(letthird_objinroot_obj[second_obj]){sum+=root_obj[second_obj][third_obj];}console.log(`${second_obj}-->${sum}`);}};add(data);
添加回答
举报
0/150
提交
取消