Here is my problem:
const data : [
{labelSlug: 'cola', category: 'catering', subCategory: 'drinks', provider: 'coca cola'},
{labelSlug: 'cola', category: 'catering', subCategory: 'drinks', provider: 'coca cola'},
{labelSlug: 'fanta', category: 'catering', subCategory: 'drinks', provider: 'coca cola'},{labelSlug: 'activities1', category: 'activities', subCategory: 'activitiesSub1', provider: 'blabla'},
{labelSlug: 'activities2', category: 'activities', subCategory: 'activitiesSub1', provider: 'blabla'},
{labelSlug: 'equipments1', category: 'equipments', subCategory: 'equipmentsSub1', provider: 'blabla'},
{labelSlug: 'equipments2', category: 'equipments', subCategory: 'equipmentsSub2', provider: 'blabla'}
{labelSlug: 'cola', category: 'catering', subCategory: 'drinks', provider: 'coca cola'},
]
I'm trying to get something like this for each category and subCategory:
{
catering : [
drinks : [
{ labelSlug: cola, provider: coca cola, count: 3 },
{ labelSlug: fanta, provider: coca cola, count: 1 }
]
]
}
The problem is I don't know how to set up this, I've tried all I could do:
const array = data.map((elem) => {
const item = {};
const sub = elem.subCategory;
const cat = elem.category;
// i've tried many things like that just to get everything in the right place (I didnt try to get the count part yet)
// item[cat[sub]].labelSlug = elem.labelSlug;
// item[cat][sub].labelSlug = elem.labelSlug;
// item[cat[sub.labelSlug]] = elem.labelSlug;
// const item = {
// [`${cat}`] : {
// [`${sub}`] : {
// labelSlug: elem.labelSlug
// }
// }
// }
return item;
})