if property is same group javscript

Solutions on MaxInterview for if property is same group javscript by the best coders in the world

showing results for - "if property is same group javscript"
Lynda
10 May 2019
1var xobj = [
2    { role:"Organize Admin", role_id:"id1", permission_name:"View All Users",active: "true" },
3    { role:"Organize Admin", role_id:"id1", permission_name:"Create users", active: "true" },
4    { role:"Organize Admin", role_id:"id1", permission_name:"Edit users", active: "true" },
5    { role:"System Admin", role_id:"id2", permission_name:"Edit users", active: "true" },
6    { role:"System Admin", role_id:"id2", permission_name:"Edit users", active: "true" },
7];
8var groups = {};
9xobj.forEach(obj => {	
10    if(!groups.hasOwnProperty(obj.role_id)){
11        groups[obj.role_id] = [];
12    }
13    groups[obj.role_id].push(obj);
14})
15console.log(groups)