I am currently working on a project in which I have an array of objects, each with "attribute" and "variation".
I need to group them as one object per attribute having the "attribute" and a list of "variations".
Sample Input:
[
{
"attribute": "Pack",
"variation": "full"
},
{
"attribute": "Size",
"variation": "M"
},
{
"attribute": "Color",
"variation": "blue"
},
{
"attribute": "Size",
"variation": "X"
},
{
"attribute": "Color",
"variation": "red"
},
{
"attribute": "Pack",
"variation": "half"
}
]
Expected Output:
[
{
"attribute": "Pack",
"variations": ["full", "half" ]
},
{
"attribute": "Size",
"variations": ["M", "X"]
},
{
"attribute": "Color",
"variations": ["blue", "red"]
},
]