Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda