This is a sample script for converting the values of Google Spreadsheet to an object using Google Apps Script.
I have a minor obsession with methods for converting Google Sheets data to an object array. Over the years I’ve documented various approaches I’ve developed on my personal site, like this one, but this solution from Kanshi Tanaike has to be my new favourite:
function myFunction() { const sheetName = "Sheet1"; const [headers, ...rows] = SpreadsheetApp.getActiveSpreadsheet() .getSheetByName(sheetName) .getDataRange() .getValues(); const res = rows.map((r) => headers.reduce((o, h, j) => Object.assign(o, { [h]: r[j] }), {}) ); console.log(res); }
Source: Converting Values of Google Spreadsheet to Object using Google Apps Script
Member of Google Developers Experts Program for Google Workspace (Google Apps Script) and interested in supporting Google Workspace Devs.