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

247
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
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