Grouping and flattening array of objects by multiple keys : <p>I'm trying to group by and flatten this array of objects:</p>

<pre><code>const data = [
            { RoleId: 1, RoleName: 'Admin', Permissions: 1 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 38 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 4 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 18 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 4001 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 30 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 20 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 2 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 10 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 99 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 5 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 22 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 4002 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 34 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 32 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 3 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 14 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 6 },
            { RoleId: 1, RoleName: 'Admin', Permissions: 26 },
            { RoleId: 2, RoleName: 'AgencyAdmin', Permissions: 10 },
            { RoleId: 2, RoleName: 'AgencyAdmin', Permissions: 3 },
            { RoleId: 2, RoleName: 'AgencyAdmin', Permissions: 4001 },
            { RoleId: 2, RoleName: 'AgencyAdmin', Permissions: 18 },
            { RoleId: 2, RoleName: 'AgencyAdmin', Permissions: 4002 },
            { RoleId: 2, RoleName: 'AgencyAdmin', Permissions: 30 },
            { RoleId: 2, RoleName: 'AgencyAdmin', Permissions: 2 },
            { RoleId: 3, RoleName: 'InstituteAdmin', Permissions: 30 },
            { RoleId: 3, RoleName: 'InstituteAdmin', Permissions: 6 },
            { RoleId: 3, RoleName: 'InstituteAdmin', Permissions: 10 },
            { RoleId: 3, RoleName: 'InstituteAdmin', Permissions: 2 },
            { RoleId: 3, RoleName: 'InstituteAdmin', Permissions: 4002 },
            { RoleId: 3, RoleName: 'InstituteAdmin', Permissions: 18 },
            { RoleId: 3, RoleName: 'InstituteAdmin', Permissions: 3 },
            { RoleId: 3, RoleName: 'InstituteAdmin', Permissions: 4001 }
        ];
</code></pre>

<p>I've tried using lodash's groupBy method but I am unable to group by multiple keys and tried using zipObject as well but I was unable to get the expected results</p>

<pre><code>groupBy(data, 'RoleId')
</code></pre>

<p>Gives me an array that's grouped by the RoleId but the same doesn't work using an array of keys</p>

<p>What I want the resulting array to look like is as follows:</p>

<pre><code>[
{RoleId: 1, RoleName:'Admin', Permissions: [1, 38, 4, 18, ...]},
{RoleId: 2, RoleName:'AgencyAdmin', Permissions: [1, 38, 4, 18, ...]},
{RoleId: 3, RoleName:'InstituteAdmin', Permissions: [1, 38, 4, 18, ...]},
]
</code></pre>

<p>Does someone know how I can tackle this problem? Any help would be appreciated. Thank you!</p>
