I have this object:
const data = {
Jan: [{product: 'Shirt', num: '13'}, {product: 'Shoes', num: '15'}],
Feb: [{product: 'Shirt', num: '22'}, {product: 'Shoes', num: '1'}],
Mar: [{product: 'Shirt', num: '15'}, {product: 'Shoes', num: '25'}]
}
I need to create another object that looks like this:
const data = {
labels: ['Jan', 'Feb', 'Mar'],
datasets: [
{
label: 'Shirt',
data: [13, 22, 15]
},
{
label: 'Shoes',
data: [15, 1, 25]
}
]
}
The object above is for a chartJs. The data array in the datasets array, correspont to each value for the product per month.
Thank you in advance
labelsareObject.keys(data). The datasets are grouped. You can find dozens of duplicates.labelsfrom the keys in the object you have. And you could loop over the data you have (maybe more than once) to build yourdatasetsand thedatawithin them.