Was not able to put entire question in the title. I have an array of objects and each object has two key values. first key value is a string and the second is another array of objects.
I need to iterate over this array so that I only have unique master names. if the name exists in new array already then only push the related array to the corresponding object. I hope this makes some kind of sense to who is reading this.
Example of array i am wanting to iterate over:
[
{master: 'Omni Mixer Homogenizer', related: [{_id: "59f5f1fe7d079b6be8fdef5c", id: 75, product_name: "product name"}]},
{master: 'Omni Mixer Homogenizer', related: [{_id: "59f5f1fe7d079b6be8fdef5e", id: 89, product_name: "product name"}]},
{master: 'μHB MICRO HOMOGENIZER', related: [{_id: "59f5f1fe7d079b6be8fdef5r", id: 102, product_name: "product name"}]},
{master: 'μHB MICRO HOMOGENIZER', related: [{_id: "59f5f1fe7d079b6be8fdef5f", id: 67, product_name: "product name"}]},
{master: 'Omni Mixer Homogenizer', related: [{_id: "59f5f1fe7d079b6be8fdef5z", id: 92, product_name: "product name"}]},
]
Based on the array above i want to get a result that looks like this:
[
{master: 'Omni Mixer Homogenizer', related: [{_id: "59f5f1fe7d079b6be8fdef5c", id: 75, product_name: "product name"}, {_id: "59f5f1fe7d079b6be8fdef5e", id: 89, product_name: "product name"},{_id: "59f5f1fe7d079b6be8fdef5z", id: 92, product_name: "product name"}]},
{master: 'μHB MICRO HOMOGENIZER', related: [{_id: "59f5f1fe7d079b6be8fdef5r", id: 102, product_name: "product name"}, {_id: "59f5f1fe7d079b6be8fdef5f", id: 67, product_name: "product name"}]},
]
Any help would be greatly appreciated, thank you.