When I output the Array in my console, it looks like this:
for (let index = 0; index < employeeList.length; index++)
this for loop doesn't work, because length is 0. I tried different methods, like
Object.keys(myObj).length;
or others from Object.
I don't know how to iterate through this Object Array. I also don't get how I could access an index value through: for (var key in employeeList) and get for example the employeeId.
Could you help me?:)
Full Code :
public selectWorkingHourListForCurrentMonthAndEveryEmployee(
month: Date
): Observable<WorkingHours[]> {
const firstDay = new Date(month);
firstDay.setDate(1);
const lastDay = new Date(
firstDay.getFullYear(),
firstDay.getMonth() + 1,
0
);
const employeeList: Employee[] = [];
let workingHoursSummedUp: WorkingHours[] = [];
this.employeeService.getAllEmployees().then((res) => {
employeeList.push(...res);
});
console.log(employeeList)
if (employeeList) {
for (let index = 0; index < employeeList.length; index++) {
this.workingHoursService
.getWorkingHours(
employeeList[index].employeeId,
firstDay,
lastDay,
true
)
.then((res) => {
workingHoursSummedUp.push(...res);
});
}
}