Array “includes” method fails in Google Apps Scrip

2020-04-06 06:52发布

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 true
    var proof = array1.includes("A"); // 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 true
  var proof = array1.indexOf("A"); // Works fine
  Logger.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?

Thanks,

0条回答
登录 后发表回答