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

160
Visualizações
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
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