got the following array:
const myObjects = [{
id: '1',
name: 'name1',
subs: [
{
id: '1',
title: 'subName1'
},
{
id: '2',
title: 'subName2'
}
]
},
{
id: '2',
name: 'name2',
subs: [
{
id: '2',
title: 'subName2'
},
{
id: '3',
title: 'subName3'
}
]
}]
need to group by 'subs' values to create new array of objects with names of original objects they were into:
const mySubs = [
{
title: 'subName1',
objects: ['name1']
},
{
title: 'subName2',
objects: ['name1', 'name1']
},
{
title: 'subName3',
objects: ['name2']
}
]
Whats the best way to do this? Could lodash be of any help