Utilizing an API to retrieve holidays and their corresponding dates, I extracted values from a JSON file and organized them into an array of arrays.
function getHolidays(){
(...)
var ulHoliday = new Array();
var txt = JSON.parse(this.responseText);
const holidays = txt.response.holidays;
for(hd of holidays){
let holidayName = hd.name;
let holidayDate = hd.date.iso;
ulHoliday.push({name: holidayName, date: holidayDate});
}
return ulHolidays;
}
While the entire array-object (ulHolidays) displays correctly when outputted, accessing items afterwards returns undefined. -_-
console.log(getHolidays()); // ulHolidays
console.log(getHolidays()[0].name); // undefined
^ The first log works as expected but the second one returns undefined. ^
This is the console output for ulHolidays.
[]
0: {name: "Second Advent Sunday", date: "2020-12-06"}
1: {name: "Saint Nicholas Day", date: "2020-12-06"}
2: {name: "Third Advent Sunday", date: "2020-12-13"}
3: {name: "Remembrance Day for Roma and Sinti killed by Genocide", date: "2020-12-19"}
4: {name: "Fourth Advent Sunday", date: "2020-12-20"}
5: {name: "December Solstice", date: "2020-12-21T11:02:20+01:00"}
6: {name: "Christmas Eve", date: "2020-12-24"}
7: {name: "Christmas Day", date: "2020-12-25"}
8: {name: "Boxing Day", date: "2020-12-26"}
9: {name: "New Year's Eve", date: "2020-12-31"}
length: 10
__proto__: Array(0)