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

142
Visualizações
How to turn form responses object into a 2D array with the 1st row being the key/header and the 2nd the values/answers using GAS?

Here's how the incoming data arrives:

let e = {"authMode":"FULL","namedValues":{"Question 1":["Answer question 1"],"Question 2":["Answer question 2"],"Question 3.":["Answer Question 3"]}}

This should look like this:

[
 ["Question 1", "Question 2", "Question 3"],
 ["Answer question 1", "Answer question 2", "Answer question 3"]
]

I'll be working on getting the headers to match the destination sheet column headers and, therefore, the object above would need to be converted to a similar format.

How can this be done using Google Apps Script? I've seen some example, but none found on this one precisely.

Thank you!

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Is this something like that ?

   const e = { "authMode": "FULL", "namedValues": { "Question 1": ["Answer question 1"], "Question 2": ["Answer question 2"], "Question 3.": ["Answer Question 3"] } }
        
   const res = Object.entries(e.namedValues).reduce((acc, [questionNumber, answer]) => {
            acc[0].push(questionNumber)
            // spread answer because answer is an array
            acc[1].push(...answer)
            return acc
    }, [[], []])

or a more compact way less comprehensible maybe

const res = Object.entries(e.namedValues).reduce((acc, [questionNumber, answer]) => [[...acc[0], questionNumber],[...acc[1], ...answer]] ,[[],[]]))
about 4 years ago · Juan Pablo Isaza Relatório

0

This will work even if you have edited the form

Editing the form often cause the number of available answers to a given question to grow.

function onMyForm(e) {
  const arr = Object.keys(e.namedValues).reduce((a,c) => {
    if(c && c.length > 0 && !a.hasOwnProperty(c)) {
      a[1].push(e.namedValues[c][e.namedValues[c].length - 1]);
      a[0].push(c);
    }
    return a;
  },[[],[]])
  return arr;
}
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