Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda