I'm having trouble grouping some data using JavaScript .
I have the following array of objects that return from the database and send it to view :
var object = [
{ data: 1, categories: "Branca", name: "Feminino" },
{ data: 1, categories: "Parda", name: "Masculino" },
{ data: 2, categories: "Branca", name: "Masculino" },
];
From it, I need to generate two more arrays grouped so I can send it to a chart in Highcharts .
I would like to get the following result:
categories: ["Parda", "Branca"]
series: [{
name: "Masculino",
data: [1, 2]
}, {
name: "Feminino",
data: [0, 1]
}]
I have already tested some possibilities, I did the array of categories , it was quite simple, but the array series > that complicated.
Can anyone help me? Thank you!