Looking at the object below:
a = [
{id: 1, comp: 'ans', stat: 'www', value: ['1', '2']},
{id: 2, comp: 'qsn', stat: 'xxx', value: ['a', 'b']},
{id: 3, comp: 'ans', stat: 'yyy', value: ['3', '4']},
{id: 4, comp: 'qsn', stat: 'zzz' ,value: ['c', 'd']}
]
I am seeking an optimal method to combine the value arrays within objects where the key comp
matches and retain the other properties as they are for the first element, while concatenating only the values
array. The desired output in this case is :
[
{id: 1, comp: 'ans', stat: 'www', value: ['1', '2', '3', '4']},
{id: 2, comp: 'qsn', stat: 'xxx', value: ['a', 'b', 'c', 'd']}
]