📌  相关文章
📜  如果属性是同一组 javscript - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:33.658000             🧑  作者: Mango

代码示例1
var xobj = [
    { role:"Organize Admin", role_id:"id1", permission_name:"View All Users",active: "true" },
    { role:"Organize Admin", role_id:"id1", permission_name:"Create users", active: "true" },
    { role:"Organize Admin", role_id:"id1", permission_name:"Edit users", active: "true" },
    { role:"System Admin", role_id:"id2", permission_name:"Edit users", active: "true" },
    { role:"System Admin", role_id:"id2", permission_name:"Edit users", active: "true" },
];
var groups = {};
xobj.forEach(obj => {    
    if(!groups.hasOwnProperty(obj.role_id)){
        groups[obj.role_id] = [];
    }
    groups[obj.role_id].push(obj);
})
console.log(groups)