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

159
Views
App Script Array Push() in loop Optimization

I'm looking to improve my array push inside loops but I noticed that every time my function is being called (in a loop manner) and executing this lines of code, it gets slower and slower. It is fast when I run this function once, but it gets longer when ran multiple times via loop.

My goal is to get the values from spreadsheet and assign them to an array with a specific arrangement so I can retrieve those data accordingly.

I need to have the spreadsheet call in the loop as I need to extract the address from the array parameter.

function testing(dataCollected){
 var i=0;
 var finalArray=[];
 
 while(i <=dataCollected.length){
  projCode = dataCollected[i][0];
  unitNo = sheet.getRange(dataCollected[i][1]).getValues();
  hours = sheet.getRange(dataCollected[i][2]).getValues(); 
 
  for (var j=0; j<=81; j++){
     finalArray.push([projCode,unitNo[j][0],hours[j][0]);
  }
  i++;
 }
}

Does using push() create an overhead in this situation as it gets larger as I append row in it? Can someone advise what is the best approach to do in this setup. Thanks.

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!