Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda