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

131
Views
Run code after full execution of "for of" loop

I am learning "ReactJS".
I am using a function to upload multiple files :

const handleFileUpload = (e) => {
    const files = e.target.files;
    if (!files) return false;
    let formD = new FormData();
    for (const file of files) {
      const type = file.type.split("/")[0]; // type of the file
      const filename = file.name; // name of the file
      // file reader to preview file
      let reader = new FileReader();
      reader.onload = () => {
        formD.append("fileList", file, filename);
        setSelectedFileForUpload((prevState) => [
          ...prevState,
          {
            file: reader.result,
            type: type,
            name: filename,
          },
        ]);
      };
      reader.readAsDataURL(file);
    } // for loop ---ENDS---
       // Lines of code given below should only execute after for loop completed.
       const apiData = {
         documents: formD,
         accountId: params.accountID,
       };
       dispatch(actions.fileUpload(apiData));
  };

So I want to run given below code after the for loop completed :

const apiData = {
      documents: formD,
      accountId: params.accountID,
    };
dispatch(actions.fileUpload(apiData));
about 4 years ago · Juan Pablo Isaza
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!