Using flat() on array works only during debugging, otherwise getting error

2,097 views
Skip to first unread message

Kamil Tamaka

unread,
Apr 10, 2023, 1:26:01 PM4/10/23
to Google Apps Script Community
Hello,
I encounter with following problem. Let's assume code. It grabbs data from M2:M, and filter empty rows.

function foo() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var row = 2;
  var column = 13;
  var data;
  data = sheet.getRange(rowcolumnsheet.getLastRow() - 1).getValues().flat().filter(Boolean);
}

When I debug code, it looks pretty nice. Empty rows are filtered and instead hundreds of rows, only filled shows:values.png

However, when I run that function, I am getting "TypeError: The flat function could not be found in the object" (translated, despite English on Google services, errors shows in my national language for unkown reason).

values2.png

I noticed this issue when I wanted to receive data using POST it shown as response.

Why does it only happen during execution, not debugging? How can I fix it?
Thank you in advance.


Dametrius King

unread,
Apr 10, 2023, 1:54:26 PM4/10/23
to Google Apps Script Community
I see from the first screenshot that you're using the Rhino runtime. Do you get the same error when you Enable Chrome V8 runtime?

Kamil Tamaka

unread,
Apr 10, 2023, 2:31:25 PM4/10/23
to Google Apps Script Community
Oh, I didn't notice it might be caused by the Rhino rountime. I though flat() is not part of that engine.
Meanwhile I made workaround for myself:
     data = sheet.getRange(rowcolumnsheet.getLastRow() - 1).getValues().filter(function(row) {
      return row[0] !== '';
    });

which got the job done.

However, I enabled it tested and code works now with flat(). Thank you for fast answer :)
Reply all
Reply to author
Forward
0 new messages