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

150
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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