Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!