I have an array of objects that each contain two categories, one of these categories represents a group.
[
{
"uuid": 123,
"group": "test_group"
},
{
"uuid": 321,
"group": "test_group"
},
{
"uuid": 432,
"group": "test_group2"
}
]
I'm looking to generate a JSON response that has categorized them by their groups.
{
"objects": [
{
"group": "test_group",
"items": [
{
"uuid": 123
},
{
"uuid": 321
}
]
},
{
"group": "test_group2",
"items": [
{
"uuid": 432
}
]
}
]
}
At the moment I've accomplished this by first iterating over and creating a set of all of the groups involved, and then iterating again and grouping them appropriately. I was wondering if there was a more succinct way of doing this, perhaps using some of the new operators introduced in ES6.