so my team and I are currently working on a trading app... My current task is to create a watchlist for the user, which I sort of have an idea how to do it, however, to display the current price for each individual stock I need to call the api and assign the price to the ticker of the stock, then I push it to my array of objects, but it continues to return empty for some reason.... this is the code....
Watchlist.find({authorId: userId}).then((watchList) => {
const arrOfObj = []
for (let i = 0; i < watchList.length; i++) {
const ticker = watchList[i].tickerId
finnhubClient.quote(ticker, (error, data, response) => {
let prices = data.c;
arrOfObj.push({ticker: ticker, price: prices})
console.log(testArr)
})
};
console.log('this is array of obj',arrOfObj)
The console.log inside of the for loop returns some arrays with objects in it, but the one outside doesn't it just returns empty. now this is where my dilemma comes in, I need to have a variable to pass to my hbs so I can use it and display the values, but if I render inside for loop it returns an error obviously since it tries to render multiple times. So if anyone has any ideas or suggestions I would really appreciate it. thank you in advance.