I have an object and there are some similarities with the type and id. If the type and the id match, I would like to change content into an array and store all the relevent contents there.
I can’t seem to wrap my head around objects and mapping. Any help would greatly appreciated. Thank you.
[{
type: 'movs',
id: '1001',
content: '111'
},
{
type: 'books',
id: '1001',
content: '222'
},
{
type: 'books',
id: '1001',
content: '333'
},
{
type: 'books',
id: '1002',
content: '444'
},
{
type: 'movs',
id: '1001',
content: '112'
},
{
type: 'movs',
id: '1005',
content: '113'
}]
to become
[{
type: 'movs',
id: '1001',
content: ['111', '112']
},
{
type: 'movs',
id: '1005',
content: ['113']
},
{
type: 'books',
id: '1001',
content: ['222', '333']
},
{
type: 'books',
id: '1002',
content: ['444']
}]
Edited: quotes