I have the following array:
const a = [{
Name: 'martha',
Surname: 'james',
Type: 'student',
},
{
Name: 'Meredith',
Surname: 'Napier',
Type: 'Teacher',
},
{
Name: 'Julie',
Surname: 'Schrutt',
Type: 'student',
}
]
I need to convert in the following format:
const a = [{
Type: 'student',
Names: [{
Firstname: 'martha',
Lastname: 'james'
},
{
Firstname: 'Julie',
Lastname: 'schrutt'
}
],
},
{
Type: 'Teacher',
Names: [{
Firstname: 'meredith',
Lastname: 'Napier'
}, ],
}
I have tried lodash grouping, object.entries, array map, reduce, but not able to figure out how to do it.