Here is the array I am working with:
var arr = [
{
count: 27,
dataRil: "08/06/21",
subCateg: "FISH",
},
{
count: 22,
dataRil: "08/06/21",
subCateg: "DOG",
},
{
count: 28,
dataRil: "09/06/21",
subCateg: "FISH",
},
{
count: 18,
dataRil: "09/06/21",
subCateg: "DOG",
},
{
count: 1,
dataRil: "09/06/21",
subCateg: "CAT",
},
{
count: 1,
dataRil: "09/06/21",
subCateg: "BIRD",
},
];
I need to group this array by category and extract the counts into a new array. How can I accomplish this?
The desired output should be:
var datasets = [
{
label: "FISH",
data: [27, 28],
},
{
label: "DOG",
data: [22, 18],
},
{
label: "CAT",
data: [0, 1],
},
{
label: "BIRD",
data: [0, 1],
},
];