I have an array of objects containing various items:
[
{
CATEGORY:"Fruits"
ITEM_AVAIL:true
ITEM_NAME:"Apple"
ITEM_PRICE:100
ITEM_UNIT:"per_kg"
ITEM_UPDATED:Object
ORDER_COUNT:0
},
{
CATEGORY:"Vegetables"
ITEM_AVAIL:true
ITEM_NAME:"Aloo"
ITEM_PRICE:1000
ITEM_UNIT:"per_kg"
ITEM_UPDATED:Object
ORDER_COUNT:0
}
]
I am looking to create a new object where each key corresponds to a category, holding the array of item objects within that category. For instance:
{
Fruits: [
{
CATEGORY:"Fruits"
ITEM_AVAIL:true
ITEM_NAME:"Apple"
ITEM_PRICE:100
ITEM_UNIT:"per_kg"
ITEM_UPDATED:Object
ORDER_COUNT:0
},
//more fruits
]
Vegetables: [
{
CATEGORY:"Vegetables"
ITEM_AVAIL:true
ITEM_NAME:"Aloo"
ITEM_PRICE:1000
ITEM_UNIT:"per_kg"
ITEM_UPDATED:Object
ORDER_COUNT:0
},
//more vegetables
]
}
This new object will be organized based on the category of each item.