I'm trying to merge a set of strings in an array based on a series of matching properties and remove the items that were duplicates.
My current array:
{id: "12", value: "Option 1"},
{id: "55", value: "Option A"},
{id: "55", value: "Option B"},
{id: "55", value: "Option C"},
{id: "55", value: "Option D"},
{id: "106", value: "Option 1"}
I want to merge all items with the id of '55' so my array will look like this:
{id: "12", value: "Option 1"},
{id: "55", value: "Option A, Option B, Option C, Option D"},
{id: "106", value: "Option}
I can only manage to merge the first 2 items using a for loop and checking the -1 sibling and can't work out to do this without serious bloat to my code.
Any advice would be appreciated.