Hi, I hope you are well, I have a problem which I can not solve. having the following json I want to group by ** state * to then create a new example:
[{
"area": "YUMBO",
"state": "NOT"
},
{
"area": "ZARZAL",
"state": "VCAU"
},
{
"area": "PUERTO CARRENO",
"state": "VIC"
},
{
"area": "SANTA ROSALIA",
"state": "VIC"
}
]
which I wish so:
[{"NOT":{"YUMBO"},
"VCAU":{"ZARZAL"},
"VIC":{"PUERTO CARRENO","SANTA ROSALIA"}
}]
[{ "NOT": {"YUMBO"}, "VCAU": {"ZARZAL"}, "VIC": {"PUERTO CARRENO", "SANTA ROSALIA"} }]
What I have so far is this where I create an array where I store the state without repeating but I would not know how to add the area part as appropriate, thank you very much
b=[]
c=[]
for (i = 0; i < a.length; i++) {
if(b.includes(a[i].state)){
}else{
b.push(a[i].state);
}
}