Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!