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

241
Vistas
Javascript "for of" loop not returning value
async function getMultiBalances() {
  let chains = await getAllChains();
  let address = await getAddress();
  let totalBalances = [];

  for (let chain of chains) {
    let chainId = chain.chain_id;
    let balances = await getMultichainBalancesArray(chainId, address);
    if (balances != undefined) {
      totalBalances = [...balances, ...totalBalances];
    }
  }
  console.log(totalBalances);
  return totalBalances;
}

The above code console logs nothing and returns nothing.

Now.. If I move the console log and return statement into the "for of" loop it will return the first iteration and work fine. I don't understand why I can't return the final value outside of the for of loop to get the array I actually want.

async function getMultiBalances() {
  let chains = await getAllChains();
  let address = await getAddress();
  let totalBalances = [];

  for (let chain of chains) {
    let chainId = chain.chain_id;
    let balances = await getMultichainBalancesArray(chainId, address);
    if (balances != undefined) {
      totalBalances = [...balances, ...totalBalances];
    }
    console.log(totalBalances);
    return totalBalances;
  }
}
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