*Not the same as the flagged question. I don't just want to delete the duplicates; I want to consolidate the values of another property of the object to be removed.
For the following object:
orderedGroups: [ { parent: 'Components', subgroups: [ 'alphaselector' ] },
{ parent: 'Utilities', subgroups: [ 'colors' ] },
{ parent: 'Test Group', subgroups: [ 'component-test-alpha' ] },
{ parent: 'Document', subgroups: [ 'fixedtableheaders' ] },
{ parent: 'Utilities', subgroups: [ 'svgicons' ] },
{ parent: 'Utilities', subgroups: [ 'typography' ] } ]
How can I remove objects with duplicate parent entries while consolidating the corresponding subgroups?
Desired output:
orderedGroups: [ { parent: 'Components', subgroups: [ 'alphaselector' ] },
{ parent: 'Utilities', subgroups: [ 'colors', 'svgicons', 'typography' ] },
{ parent: 'Test Group', subgroups: [ 'component-test-alpha' ] },
{ parent: 'Document', subgroups: [ 'fixedtableheaders' ] } ]
What I have so far/where I'm stuck:
for (let val of Object.values(orderedGroups)) {
if (orderedGroups.hasOwnProperty(val.parent)) {
// remove duplicate objects and consolidate corresponding subgroups
}
}
*Note: I cannot import modules; must be plain js.