小编Ric*_*edo的帖子

数组“包含”方法在Google Apps脚本中失败

我试图对Google Apps脚本中的数组使用“包含”方法,但由于“在对象1,4,3,7中找不到函数包含而失败(第4行,文件“ test_array”),它失败。这是代码:

    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);
}
Run Code Online (Sandbox Code Playgroud)

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

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);
}
Run Code Online (Sandbox Code Playgroud)

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

谢谢,

javascript google-apps-script

5
推荐指数
1
解决办法
1336
查看次数

标签 统计

google-apps-script ×1

javascript ×1