Does anyone know a simple way to group an array with nested array?
For example, i have an array of animals:
[
['Cat', 'Dog', 'Monkey'],
['my pet', 'it is animals', 'terrestrial animals']
]
I want to make new array with format that’s grouped by ['Cat', 'Dog', 'Monkey']
:
[
{
groupTitle: 'Cat',
relations: ['my pet', 'it is animals', 'terrestrial animals']
},
{
groupTitle: 'Dog',
relations: ['my pet', 'it is animals', 'terrestrial animals']
},
{
groupTitle: 'Monkey',
relations: ['my pet', 'it is animals', 'terrestrial animals']
}
]
How can i do it?
Thanks!