Array includes method fails in Google Apps Script

2024/2/27 7:30:49

I was trying to use the "includes" method for an array in Google Apps Script but it fails with "Cannot find function includes in object 1,4,3,7. (line 4, file "test_array"). Here is the code:

    function test_array() {var array1 = [1,4,3,7];Logger.log(Array.isArray(array1)); // returns truevar proof = array1.includes("A"); // proof fails with "Cannot find function includes in object 1,4,3,7. // (line 4, file "test_array")Logger.log(proof);

In the logs I see that the Logger.log() returns true. I worked around this with:

function test_array() {var array1 = [1,4,3,7];Logger.log(Array.isArray(array1)); // returns truevar proof = array1.indexOf("A"); // Works fineLogger.log(proof);

But I still want to know why the includes method fails on a variable the compiler says is an array. Could it be that it is considering it to be an array of arrays, i.e. an object?



It was/is not supported in rhino runtime. With upgrade to v8, Array.includes is supported and should be preferred instead of Array.indexOf in all cases.

Related Q&A

communicating with data or methods in vue and addEventListener [duplicate]

This question already has answers here:How to access the correct `this` inside a callback(15 answers)Closed 6 years ago.Im having trouble communicating with my data or methods with this code,created() …

How can I use the same error page for multiple error codes in Tomcat?

Im trying to send plain text error messages from a tomcat servlet, so that the responses may be presented to the user by the application.I have the following in my web.xml:<error-page><error-c…

How to lock the first word of a textarea?

Basically I need to create a textarea that is character limited, but will have a single word at the beginning, that they cant change.It needs to be a part of the textarea, but I dont want users to be a…

Change the color of a text in div using jquery contains

Here the whole text inside the div gets red color. but I need only the "bar" word color to be changed <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:…

Given an x,y coordinate, I need to find all html elements underneath it

I am building an app where I repeatedly need to get lists of html elements sitting under a specific location (x,y relative to the viewport, e.g.). I am considering the following approaches, but none a…

ng-repeat list in AngularJS isnt updated when an ajax call changing its value

Im totally confused. Why doesnt my ng-repeat refresh when theres an ajax call changing its value? Ive seen many Q&As here, but none of them talked about ajax call.HTML:<div class="row"…

Vue - when and why using $el

Ive found this answer here: and i wonder why .$el was used here, and also why does it not work without the el element?

Detecting my own Firefox extension from a webpage

I am trying to find an easy way to detect if my extension is installed in Firefox 3.6. This should be done from a webpage, probably using javascript.Ive read a lot of blogs that says that I should try …

d3 — Progressively draw a large dataset

Im using d3.js to plot the contents of an 80,000 row .tsv onto a chart.The problem Im having is that since there is so much data, the page becomes unresponsive for aprox 5 seconds while the entire data…

Highlight div onclick [duplicate]

This question already has answers here:How can I highlight a selected list item with jquery?(4 answers)Closed 8 years ago.I have a question, what jQuery code need to be used, to highlight DIV in list …