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

253
Vistas
Why does the function fail after UrlFetchApp.fetchAll () is executed?

After executing the useFetchAll function, I pass the response value to the stringform function, and I get an error

TypeError: A.forEach is not a function

In the example, I made the variable asdf and copied the Logger.log (response) value into it, the stringform function works and returns an array. Why does the function throw an error when the value is (response)?

    // Using UrlFetchApp.fetchAll()
    function useFetchAll(req) {
    var response = UrlFetchApp.fetchAll(req);
     
    var asdf=[[["a",1],["a",2],["a",3],["a",4],["a",5]], [["b",6],["b",7],["b",8],["b",9],["b",10]], [["c",11],["c",12],["c",13],["c",14],["c",15]], [["d",16],["d",17],["d",18],["d",19],["d",20]], [["e",21],["e",22],["e",23],["e",24],["e",25]]];
     
    Logger.log(response);
    Logger.log(stringform(asdf));
     
    }
     
    
   function stringform(asdf) {
    let formad = '';
      asdf.forEach(A => {
        A.forEach(r => {
          formad += r.join(',') + '%0A';
        });
      });
      return formad;
      
    }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

It's an array that's 3 deep.

function myfunction() {
  let s = '';
  var asdf = [[["a", 1], ["a", 2], ["a", 3], ["a", 4], ["a", 5]], [["b", 6], ["b", 7], ["b", 8], ["b", 9], ["b", 10]], [["c", 11], ["c", 12], ["c", 13], ["c", 14], ["c", 15]], [["d", 16], ["d", 17], ["d", 18], ["d", 19], ["d", 20]], [["e", 21], ["e", 22], ["e", 23], ["e", 24], ["e", 25]]];
  asdf.forEach(A => {
    A.forEach(r => {
      s += r.join(',')+ '\n';
    })
  })
  Logger.log(s);
}

Execution log
3:53:29 PM  Notice  Execution started
3:53:29 PM  Info    a,1
a,2
a,3
a,4
a,5
b,6
b,7
b,8
b,9
b,10
c,11
c,12
c,13
c,14
c,15
d,16
d,17
d,18
d,19
d,20
e,21
e,22
e,23
e,24
e,25
3:53:30 PM  Notice  Execution completed

You lower function would have worked but asdf was not defined in that function.

Your lower function runs like this:

function stringform(asdf) {
  var asdf = [[["a", 1], ["a", 2], ["a", 3], ["a", 4], ["a", 5]], [["b", 6], ["b", 7], ["b", 8], ["b", 9], ["b", 10]], [["c", 11], ["c", 12], ["c", 13], ["c", 14], ["c", 15]], [["d", 16], ["d", 17], ["d", 18], ["d", 19], ["d", 20]], [["e", 21], ["e", 22], ["e", 23], ["e", 24], ["e", 25]]];
    let formad = '';
      asdf.forEach(A => {
        A.forEach(r => {
          formad += r.join(',') + '\n';
        });
      });
      Logger.log(formad)
      
    }
about 4 years ago · Juan Pablo Isaza Denunciar

0

About your question of Why does the function fail after UrlFetchApp.fetchAll () is executed?, from your script and In the example, I made the variable asdf and copied the Logger.log (response) value into it, the stringform function works and returns an array. Why does the function throw an error when the value is (response)?, I thought that the reason of your issue is due to that fetchAll returns HTTPResponse[] which is an array.

For example, when one of requests req returns 2 dimensional array like [["a",1],["a",2],["a",3],["a",4],["a",5]], Logger.log(response) of var response = UrlFetchApp.fetchAll(req) shows [[["a",1],["a",2],["a",3]], [["a",1],["a",2],["a",3]]]. In your situation, I thought that the values from the muliple requests might be included in response.

If my understanding of your situation is correct, how about the following modification?

Modified script:

function useFetchAll(req) {
  var response = UrlFetchApp.fetchAll(req);
  var asdf = response.map(r => JSON.parse(r.getContentText()));
  Logger.log(stringform(asdf));
}

function stringform(asdf) {
  let formad = '';
  asdf.forEach(A => {
    A.forEach(r => {
      formad += r.join(',') + '%0A';
    });
  });
  return formad;
}

or,

function useFetchAll(req) {
  var response = UrlFetchApp.fetchAll(req);
  var values = response.reduce((t, r) => t += JSON.parse(r.getContentText()).map(c => c.join(',') + '%0A'), "");
  Logger.log(values)
}

Reference:

  • fetchAll(requests)

    Return: HTTPResponse[] — An array of HTTP response data from each input request.

about 4 years ago · Juan Pablo Isaza Denunciar
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