列表<字符串>语法错误谷歌脚本
List<String> Syntax error google script
我无法理解在Google脚本(基于Javascript)中设置数组。
我在数组中有一个我需要的国家/地区"AU"和"NZ"列表,稍后将添加到该列表。稍后我需要搜索数组以检查字符串是否与数组中的值匹配。
我尝试在谷歌脚本中以多种方式添加数组。
第一次尝试:
List<String> country_list = new ArrayList<String>();
country_list.add("AU");
country_list.add("NZ");
这会在第 1 行抛出一个Syntax error.
。
对此的变体:
第二次尝试:
var country_list = [];
country_list.add("AU")
country_list.add("NZ")
在第二行抛出错误TypeError: Cannot find function add in object .
。
第三次尝试:
var Country_List = ["AU","NZ"];
if (country_list.contains("AU")) {
// is valid
ui.alert("great success");
} else {
// not valid
ui.alert('Nope try again');
}
这将引发错误"类型错误:找不到对象中包含的函数..."
这是有道理的,所以我尝试转换为Array.asList()
.
第四次尝试:
var original_country_list = ["AU","NZ"];
List<String> country_list = Arrays.asList(original_country_list)
if (country_list.contains("AU")) {
// is valid
ui.alert("great sucsess");
} else {
// not valid
ui.alert('Nah Mate try again');
}
这会引发错误Invalid assignment left-hand side
,当使用 []
和 ()
来保持original_country_list
。使用 {}
按住original_country_list
时,它会抛出错误Missing : after property ID
。
我尝试的最后一件事是:
第五次尝试:
var original_country_list = ["AU","NZ"];
var country_list = Arrays.asList(original_country_list)
这会抛出错误ReferenceError: "Arrays" is not defined
.
抱歉,如果这很明显,但这里出了什么问题?
我在这里看到的大部分内容看起来更接近Java而不是Javascript。但是#2可以是这样的Javascript:
var country_list = [];
country_list.push("AU");
country_list.push("NZ");
3也可以轻松修复:
var Country_List = ["AU","NZ"];
if (Country_list.indexOf("AU") > -1) {
// is valid
ui.alert("great success");
} else {
// not valid
ui.alert('Nope try again');
}
相关文章:
- 谷歌地图laravel上圆圈的错误位置
- 我该如何解决“;未捕获引用错误:谷歌没有定义"?(谷歌地图API)
- Video.js+移动设备上的谷歌IMA:'点击'导致错误的事件
- 谷歌地图infowindow错误f=未定义的infowindow.js
- 谷歌地图web组件NoApiKeys错误
- "未捕获的语法错误:意外的标记<"当尝试使用谷歌'核心报告API
- 信息窗口谷歌地图点击事件给出错误
- 嵌入谷歌地图后的CSS错误
- 未捕获的类型错误:无法读取属性'fitBounds'谷歌地图(markrWithlabel js)中未定
- 谷歌图表 - 地理图表“不兼容的数据表:错误:未知地址类型
- 谷歌地图javascript多个方法错误
- 谷歌地图如何修复OVER_QUERY_LIMIT错误
- 谷歌未定义(api 映射错误)
- 谷歌地图 API 错误:属性<航点>::中的错误
- 完整的日历错误时间在点击事件谷歌日历
- 谷歌图表错误'不是数组'关于Ajax更新
- 谷歌地图API多段线创建失败;未捕获类型错误:数字不是函数;
- 未捕获的类型错误:无法读取属性'长度'未定义的谷歌地图V3
- 谷歌URL缩短器API-未压缩类型错误:未定义不是一个函数
- 使用谷歌分析来跟踪错误