I want to groupBy my array of an object into some another desired array of objects. I go through several tutorials but didn't get the appropriate output.
What I want is based on their groupBy properties I want to group all the elements
Here is my input
permissions= [
{
code: 'U00',
permission_name: 'Read User',
groupBy: 'User',
icon: 'user',
},
{
code: 'U01',
permission_name: 'Create User',
groupBy: 'User',
icon: 'user',
},
{
code: 'B00',
permission_name: 'Read Batch',
groupBy: 'Batch',
icon: 'user',
},
{
code: 'B01',
permission_name: 'Create Batch',
groupBy: 'Batch',
icon: 'user',
},
{
code: 'B10',
permission_name: 'Update Batch',
groupBy: 'Batch',
icon: 'user',
},
];
Required output
Output = [
{
label: 'User',
icon: 'user',
children: [
{
label: 'Create Users',
},
{
label: 'Read All Users',
},
],
},
{
label: 'Batch',
children: [
{
label: 'Create Batchs',
},
{
label: 'Read All Batch',
},
{
label: 'Update Batch',
},
{
label: 'Disabled Batch',
},
],
},
];
iconforBatch?