The following javascript endpoint contains list of cities in United States. I am pushing the elements to the array citiesInfo after I retrieve it from the endpoint. The array shows up when I do console.log(citiesInfo); and I can navigate through the array in console but when I do console.log(citiesInfo[0]); It shows undefined
const endpoint = 'https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json';
const citiesInfo = [];
fetch(endpoint)
.then(function(elem){
return elem.json();
})
.then(function(elem){
citiesInfo.push(...elem);
});