In the first phase, I fetch the array, which then I use to construct another query to the server. However, after this second fetch operation, I do not have access to this object.
I can see the tables - but when I try to do any operations - it returns undefined.
So it looks like fetchDetails function hasn't finished yet.
Could someone please guide me how to make it happen so I can have access to resolved result
from fetchDetails
in getData
function?
const URL = 'http://localhost:3000/stocks/';
async function getData() {
let response = await fetch(URL)
let avaibleStocks = await response.json()
let symbols = avaibleStocks.stockSymbols
let detailedRes = await fetchDetails(symbols)
// here I would like to make next operations with data from detailedRes variable
console.log(detailedRes) // I can see array with 'Value below was evaluated just now'
console.log(detailedRes[0]) // but if I try to get any access I recive Undefined
}
async function fetchDetails(symbols) {
let result = [];
symbols.forEach( async s => {
let res = await fetch(URL+s)
let details = await res.json()
await result.push(details)
})
return result
}