[{"add":"4","shul":"2000","yanba":"20"},{"add":"5","shul":"2001","yanba":"21"},{"add":"6","shul":"2002","yanba":"22"}]如上json想要处理成这样的格式,也就是把相同的属性对应的值放到一个数组里面。这里的属性名未知。{“add”:["4","5","6"],"shul":["2000","2001","2002"],"yanba":["20","21","22"],}
2 回答
料青山看我应如是
TA贡献1772条经验 获得超8个赞
vardata=[{"add":"4","shul":"2000","yanba":"20"},{"add":"5","shul":"2001","yanba":"21"},{"add":"6","shul":"2002","yanba":"22"}],obj={};data.forEach(function(d){for(varkind){if(!obj[k])obj[k]=[];obj[k].push(d[k]);}})
德玛西亚99
TA贡献1770条经验 获得超3个赞
javascriptfunctiontrans(arr){varresult={};arr.forEach(function(val){for(variinval){if(typeofresult[i]=="undefined")result[i]=[];result[i].push(val[i])}})returnresult;}简单循环处理一下就可以了。
添加回答
举报
0/150
提交
取消