I have the following object:
const original = [{
"key-8": {
"some object"
}
},
{
"key-12": {
"some object"
}
},
{
"key-12": {
"some object"
}
},
{
"key-1": {
"some object"
}
},
{
"key-8": {
"some object"
}
}
]
As you can see I have two objects with key-8
and two with key-12
.
I would like to combine them (the order does not matter) so the output will be:
{
{
"key-12": [{
"some object"
},
{
"some object"
}
]
}, {
"key-1": {
{
"some object"
}
},
{
"key-8": [{
"some object"
},
{
"some object"
}
]
}
}
}
I cannot make it works no matter what I try. I used reduce
, I used regular forEach
and other "hacks" simple do not work because TypeScript does not like them.
Can someone help please?