美文网首页
ionic数组元素分组

ionic数组元素分组

作者: Lem0nNat1on | 来源:发表于2016-11-02 10:52 被阅读92次
    $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

    相关文章

      网友评论

          本文标题:ionic数组元素分组

          本文链接:https://www.haomeiwen.com/subject/vhevuttx.html