$scope.click = function() {
// body...
var arr = [{id:1,name:"aaa"},{id:1,name:"bbb"},{id:2,name:"ccc"},{id:1,name:"ddd"},{id:2,name:"eee"},{id:3,name:"fff"}]
var group = {};
for(var i in arr){
if(group[arr[i].id]){
group[arr[i].id].push(arr[i]);
}else{
group[arr[i].id] = [arr[i]];
}
}
console.log(group)
}
结果:
QQ截图20161102105434.png
网友评论