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

238
Vistas
How to correctly pass parameters through nested functions in for loop?

I'm trying to use nodejs to run a loop functions oh_lawd_it_chonky() that is supposed to do the following: Loop target_users array passing each user to initialize() for authorization, for each given user get data using returnbigdatachunk() take that data and refine it or do something to it using process_returnbigdatachunk() push each of the results of that for each user to an array output.

I have each of the initialize(), returnbigdatachunk() and process_returnbigdatachunk() working individually and so I've omitted the details of those functions for the sake of simplicity in this post, I just can't seem to get the darn oh_lawd_it_chonky() function working. I don't quite understand how to pass through the user parameters correctly in nested functions like this. Please help if you can! Sorry this isn't quite a working example.

const target_users = ['user1', 'user2', 'user3'];

//authorize each user
function initialize(user) {
//do the stuff to get authorization
}

//loop through all the users and build an array of all the process_returnbigdatachunk
const oh_lawd_it_chonky = async () => {
for (var f = 0; f < target_users; f++) {
try {

  //get data of passed in user
  const returnbigdatachunk = async () => {
    const auth = initialize(user[target_users[f]]);

    let output = [];

    //refine data of passed in user
    const process_returnbigdatachunk = async () => {
        try {
          const data = await returnbigdatachunk();

          //push refined data into output array
          output.push(process_returnbigdatachunk)     
          console.log("crampus: " + output)
        } catch (e) {
          console.error('Failed to process returnbigdatachunk', e);
        }
      };
  };
} catch (e) {
  console.error('Failed to process returnbigdatachunk', e);
}
}
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

setTimeout in for-loop does not print consecutive values

block-scoped change you var f = 0 to let f = 0

about 4 years ago · Juan Pablo Isaza Denunciar
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