Converting Values of Google Spreadsheet to Object using Google Apps Script


This is a sample script for converting the values of Google Spreadsheet to an object using Google Apps Script.

Sample script

function myFunction() {
  const sheetName = "Sheet1";
  const [headers, ...rows] = SpreadsheetApp.getActiveSpreadsheet()
  const res = =>
    headers.reduce((o, h, j) => Object.assign(o, { [h]: r[j] }), {})
  • When this script is run, the above sample image can be retrieved.
  • In this sample script, the 1st row of the sheet is used as the header row.