数组“包含"方法在Google Apps脚本中失败 [英] Array "includes" method fails in Google Apps Script

查看:68
本文介绍了数组“包含"方法在Google Apps脚本中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用包含" Google Apps Script中数组的方法",但失败,并显示对象1,4,3,7中找不到函数". (第4行,文件"test_array").这是代码:

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"); 
     // proof fails with "Cannot find function includes in object 1,4,3,7. 
     // (line 4, file "test_array")
  Logger.log(proof);
}

在日志中,我看到Logger.log()返回true.我通过以下方法解决了这个问题:

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);
}

但是我仍然想知道为什么include方法在编译器说是数组的变量上失败.难道它正在考虑将其视为一个数组的数组,即一个对象?

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?

谢谢

推荐答案

运行时. 升级

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆