TypeError:在对象中找不到函数 [英] TypeError: Cannot find function includes in object

查看:1444
本文介绍了TypeError:在对象中找不到函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google Script的经验很少,但我试图用它来搜索电子表格的一列,并找到字符串Film Dub的所有实例(知道每个单元只能有一个)。

I have very little experience using Google Script but I was attempting to use it to search through one column of a spreadsheet and find all instances of the string "Film Dub" (knowing that there can be only one per cell).

以下是我的代码:

Below is my code:

    function filmDub() {
      var sheet = SpreadsheetApp.getActiveSheet();
      var data = sheet.getDataRange().getValues();
      for (var i = 1; i < 100; i++) {
        var s = data[i][2].toString();
        if (s.includes('Film Dub')) {
          data[5][13]++;
        }
      }
    }

但是我一直收到错误


TypeError:在对象中找不到函数让我们制作日期,电影配音,三头百老汇明星,电影电视剧院风格,精选,世界最差。 (第6行,代码文件)

让我们制作日期, ,三头百老汇明星,电影电视剧场风格,最伟大的命中,世界最差是正确的内容 data [i] [2] 来自电子表格的正确信息。我在Google脚本编辑器中使用了调试器来验证 s 是一个字符串(这是堆栈溢出的类似问题的解决方案之一),但没有解决我的问题。还有什么可能是错的?

"Let's Make A Date, Film Dub, Three Headed Broadway Star, Film TV Theater Styles, Greatest Hits, World's Worst" is the correct content of data[i][2] so it is getting correct information from the spreadsheet. I have used the debugger in Google Script Editor to verify that s is a string (this was one of the solutions to similar questions here on Stack Overflow) but that didn't fix my problem. What else could be wrong with it?

推荐答案

您应该使用indexOf和一个字符串来检查是否存在文本块。

You should use indexOf with a string to check for the existence of a text block.

function filmDub() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var data = sheet.getDataRange().getValues();
  for (var i = 1; i < 100; i++) {
    var s = data[i][2].toString();
    if (s.indexOf('Film Dub') !== -1) {
      data[5][13]++;
    }
  }
}

这篇关于TypeError:在对象中找不到函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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