1
I’m using this function to group some data that comes from the API:
function groupBy(objectArray, property) {
return objectArray.reduce(function (acc, obj) {
var key = obj[property];
if (!acc[key]) {
acc[key] = [];
}
acc[key].push(obj);
return acc;
}, {});
}
var groupedYear = groupBy(this._data, 'year');
Bring the data back correctly, in this case it brings the year 2020 and 2021;
When I give one console.log(groupedYear.length);
he returns Undefined.
I need him to return the two items, which is 2020, and 2021.
You gave it right, I’m just waiting for the time to accept the answer. Thank you.
– Mariana
And how do I get the length within 2020 for example? to give the 13 ?
– Mariana
@Mariana in this case only use
groupedYear['2020'].length
.– Phiter