var a=[{name:1,key:'a'},{name:2,key:'b'},{name:3,key:'a'},{name:3,key:'b'}]
2 回答
慕莱坞9220042
TA贡献377条经验 获得超508个赞
你好:
var a=[{name:1,key:'a'},{name:2,key:'b'},{name:3,key:'a'},{name:3,key:'b'}]; var result = new Array(); for(var index in a){ result[a[index].key] = new Array(); result[a[index].key].push(a[index]); } console.log(result);
望采纳!
weibo_青梅竹马酱_0
TA贡献27条经验 获得超64个赞
var b = {}; a.forEach(function (obj) { var array = b[obj['key']] || []; array.push(obj); b[obj['key']] = array; }); console.log(b.a.length);console.log(b.b.length);
添加回答
举报
0/150
提交
取消