I have an array that looks like this:
So as a strucutre it would be something like:
[
[
{ classNumber: '2', status: 'A', terms: [] },
{ classNumber: '32', status: 'B', terms: [] },
{ classNumber: '44', status: 'C', terms: [] }
],
[
{ classNumber: '2', status: 'B', terms: [] },
{ classNumber: '31', status: 'A', terms: [] }
],
....
]
This wierd array of objects happens because at some point, in our app, we are creating an array of reasons to object something using the same object.
I need to be able to merge the nested array of objects to look like this:
[
{ classNumber: '2', status: [ 'A', 'B' ], terms: [] },
{ classNumber: '31', status: [ 'A' ], terms: [] },
{ classNumber: '32', status: [ 'B' ], terms: [] },
{ classNumber: '44', status: [ 'C' ], terms: [] }
]
But I've been struggling with this for some days, looking for some lodash functions but still no luck...
I'm completely lost on how to achieve this. All examples look simpler, with less nested arrays. Any idea on how to merge all props for the same object key?
Thanks a lot in advance.