I have array of objects as follow:
[
{
"category": "Drinks",
"id": 1,
"name": "COLA",
"price": 0,
"type": 1
},
{
"category": "Drinks",
"id": 2,
"name": "COFFEE",
"price": 2.5,
"type": 1
},
{
"category": "Addons",
"id": 3,
"name": "Extra cheese",
"price": 5,
"type": 0
},
{
"category": "Addons",
"id": 4,
"name": "Extra vagg",
"price": 3,
"type": 0
},
]
I want to filter the data based on category name and type so the data that have same category name and same type number become together, the result be something like
[
Drinks:[
{
"id": 1,
"name": "COLA",
"price": 0,
"type": 1
},
{
"id": 2,
"name": "COFFEE",
"price": 2.5,
"type": 1
}
],
Addons:[
{
"id": 3,
"name": "Extra cheese",
"price": 5,
"type": 0
},
{
"id": 4,
"name": "Extra vagg",
"price": 3,
"type": 0
}
]
]
note that category names not always the same names as above. Hope someone can help, thanks.