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

74
Views
Array.push updates itself while using inside map function

Here I have used two new arrays for catching URL and Filename value. When I view it on console I got different values everytime like array got overwritten from previous values, Am I doing anything wrong?

downLoadFilesAsZip = async(item) => {

for (const index in item.docLinks) {
  let urlArr=[];
  let fileNameArr = [];
  const url = item.docLinks[index];
  let linkParts = url.split("?");
  let filename = linkParts[0].substring(linkParts[0].lastIndexOf('/')+1);
  urlArr.push(url);
  fileNameArr.push(filename);  
}
}

downLoadAllAsZip = () => {
  {
    this.state.docGroups.length !== 0 && this.state.docGroups.map((item) => {
      if(item.docLinks !== null && item.docLinks.length > 0){
          return(
            this.downLoadFilesAsZip(item)
          );
      }
    })
  }  
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Follow the loop. Every time your loop runs you are setting empty arrays.

let urlArr=[];
let fileNameArr = [];

bring that outside of your for loop.

about 4 years ago · Juan Pablo Isaza Report

0

Declaring array outside for loop(after import) helped to update every values, For .tsx file answer was this

type urlArr = any[];
type fileNameArr = any[];
let urlArr=[];
let fileNameArr = [];
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!