Currently, I have a list named appointments initialized outside of a function, and my code is pushing objects into this array from within that function.
var appointments = [];
async function getAllAppointmentEvents() {
var doctorList = await getAllDoctors();
// For all doctors
for (let i = 1; i < doctorList["doctorinfo"].length; i++) {
// Find their appointments
schedule = await getAppointmentsByDoctor(i).then(function (response) { return response; });
// For each appointment
if (schedule["schedules"] !== undefined) {
for (let j = 0; j < schedule["schedules"].length; j++) {
var startDate = new Date(schedule["schedules"][j]["datetime"]);
// startDate = new Intl.DateTimeFormat("")
var endDate = new Date(schedule["schedules"][j]["datetime"]);
endDate.setHours(startDate.getHours() + 1);
var result = {
title: doctorList["doctorinfo"][i][1],
start: startDate.toISOString().slice(0, 19),
end: endDate.toISOString().slice(0, 19),
color: "#C0C0C0",
groupId: doctorList["doctorinfo"][i][0]
};
appointments.push(result);
}
}
}
}
When I console.log the output, I get an empty array that seems to contain all all the objects. But i'm unable to access the objects by appointments[0]
. I've also tried printing out Object.keys(appointments)
and it doesn't have any keys either. When I console.log inside the function, the array is accessible as per normal.
The output I get when I console.log the list from outside of the function: output
I need help accessing the objects from outside of the function. Thanks!