Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
my array returns empty even after pushing the values from api

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!