只是想知道,有没有办法为.includes方法添加多个条件,例如:
var value = str.includes("hello", "hi", "howdy");
Run Code Online (Sandbox Code Playgroud)
想象逗号状态"或"(它现在询问字符串是否包含hello hi 或 howdy.所以只有一个,只有一个条件为真.
有没有办法做到这一点?
我试图对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方法在编译器说是数组的变量上失败。难道它正在考虑将其视为数组的数组,即对象?
谢谢,