---
title: "Converting Google Sheets cell values to an object array with heading keys using Google Apps Script"
author: "Martin Hawksey"
date: 2022-03-18T16:57:21+00:00
modified: 2022-03-19T08:02:32+00:00
canonical_url: https://pulse.appsscript.info/p/2022/03/converting-google-sheets-cell-values-to-an-object-array-with-heading-keys-using-google-apps-script/
markdown_url: https://pulse.appsscript.info/p/2022/03/converting-google-sheets-cell-values-to-an-object-array-with-heading-keys-using-google-apps-script.md
categories:
  - "Intermediate"
  - "Sheets"
  - "Solutions"
  - "V8"
tags:
  - "tanaikech.github.io"
featured_image: https://pulse.appsscript.info/files/2022/03/fig1.png
description: "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, but this solution from Kanshi Tanaike has to be my new favourite"
---

# Converting Google Sheets cell values to an object array with heading keys using Google Apps Script

![Converting Google Sheets cell values to an object array with heading keys using Google Apps Script](https://pulse.appsscript.info/files/2022/03/fig1.png)

> [https://tanaikech.github.io/2021/10/24/converting-values-of-google-spreadsheet-to-object-using-google-apps-script/](https://tanaikech.github.io/2021/10/24/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.

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**](https://hawksey.info/blog/2018/02/google-apps-script-patterns-using-the-destructuring-assignment-syntax-and-object-arrays-to-process-google-sheet-rows/), 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**](https://tanaikech.github.io/2021/10/24/converting-values-of-google-spreadsheet-to-object-using-google-apps-script/)

---

*Published by [Martin Hawksey](https://pulse.appsscript.info/p/author/admin/) on [Pulse](https://pulse.appsscript.info/). Original article: [https://pulse.appsscript.info/p/2022/03/converting-google-sheets-cell-values-to-an-object-array-with-heading-keys-using-google-apps-script/](https://pulse.appsscript.info/p/2022/03/converting-google-sheets-cell-values-to-an-object-array-with-heading-keys-using-google-apps-script/)*
