I am trying to create a new array of object from an existing array of object based on the common attribute (category.blocktitle) value inside the object. My array of object looks like this.
[
{
"category": {
"name": "test1111",
"val": "test111111111",
"blocktitle": ".test.0"
}
},
{
"category": {
"name": "test22",
"val": "test2222",
"blocktitle": ".test.0.test2"
}
},
{
"category": {
"name": "test1111111",
"val": "test11111111111",
"blocktitle": ".test.0"
}
},
{
"category": {
"name": "test2222",
"val": "test222222",
"blocktitle": ".test.0.test2"
}
}
]
My desired output is
[
{
"category": {
"name_val" : [
{
"name": "test1111",
"val": "test111111111"
},
{
"name": "test1111111",
"val": "test11111111111",
}
]
},
"blocktitle": ".test.0"
},
{
"category": {
"name_val" : [
{
"name": "test22",
"val": "test2222"
},
{
"name": "test2222",
"val": "test222222",
}
]
},
"blocktitle": ".test.0.test2"
}
]
I have tried reduce / map / filter but not sure what I am doing wrong.