When I try to execute this block of code this is what I get.
Line 82 where the error happens is: var group = this.detailsDate.reduce(function (r, o){
core.js:6486 ERROR TypeError: Cannot read properties of undefined (reading 'reduce') at DashboardComponent.getDatesOnly (dashboard.component.ts:82) at DashboardComponent.ngOnInit (dashboard.component.ts:56)
getDatesOnly(){
this.requestService.getAllRequests().subscribe(data=>{
JSON.stringify(data);
this.requestAllDetails=data
var alldates = this.requestAllDetails.map(t=>t.startDate)
this.detailsDate = alldates;
console.log(alldates)
})
//above code returns array containing dates only
//returns array with month + count
var monthNames = [
"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December"
];
var group = this.detailsDate.reduce(function (r, o){
var date = new Date(o);
var month = date.getMonth();
var monthName = monthNames[month];
(r[monthName]) ? r[monthName].count++ : r[monthName] = { monthName: monthName, count: 1 };
return r;
}, {});
var result = Object.keys(group).map((key) => group[key]);
console.log(result);
}