Inside a React component, I have a function (Triggered once the component is rendered) :
function getGlassesNames () {
let outputArray:string[] = getGlassesOriginal();
console.log(outputArray);
console.log(typeof outputArray);
console.log(outputArray.length);
}
console.log #1 shows '[]'.(Which, you can open it and notice that it's actually a poblated array with data)
console.log #2 shows 'Object'
but...console.log #3 shows '0'
The inner function, 'getGlassesOriginal', is being called from an utils.tsx which reads:
export function getGlassesOriginal ():string[] {
let outputArray:string[] = [];
axios
.get("https://www.thecocktaildb.com/api/json/v1/1/list.php?g=list")
.then((response)=>{
let responseDataJson=response.data.drinks;
var i=0;
for (let element in responseDataJson) {
outputArray.push(responseDataJson[element].strGlass.toString());
}
}
)
return outputArray;
}
I just don't understand why I can see in console browser the outputArray from getGlassesNames poblated correctly with data (Element[index]=value) , yet once I want to use their values, those are undefined.
Hope you can help me! Thanks in advance!!!