Home:ALL Converter>Deconstructing 2D array in Google Apps Script

Deconstructing 2D array in Google Apps Script

Ask Time:2019-01-23T06:35:42         Author:medic17

Json Formatter

I am trying to destructure a 2D array in Google Apps Script and it remains unchanged.

I found a link that explains how to destructure an array in google apps script similar to the syntax for javascript es6.

The link is https://plus.google.com/u/0/+DimuDesigns/posts/9FDJx2qe4gZ

The example they give works fine for me in as a separate function.

function readData() {
  var id = '1P4aVeFJMT9e0ijoFt262IuLlnjHte8hl2iUeU_kk-AQ'; //ID of the 
projects spreadsheet
  var ass = SpreadsheetApp.openById(id); //Initilize spreadsheet
  var sheet = ass.getSheetByName('Sheet1'); //Get sheet instence

  var row1data = sheet.getRange('A1:F1').getValues();

  [a1, b1, c1, d1, e1, f1] = [row1data];  

  //DEBUG
  Logger.log(a1);
}

expected output to log should be the data in cell A1 which is the first item in the array.

actual output is the array itself.

I am a beginner in general so a clear explanation with well commented code would be appreciated.

Author:medic17,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/54317450/deconstructing-2d-array-in-google-apps-script
yy