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

236
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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