gpt4 book ai didi

javascript - 将项目添加到逗号分隔列表的自定义 Google 表格功能

转载 作者:行者123 更新时间:2023-11-30 11:05:10 25 4
gpt4 key购买 nike

我在 Google 表格中有逗号分隔的列表,例如“apple,banana”。我需要一个函数来向这个列表中添加元素,例如 =SETADD("apple,banana","carrot"),它应该返回值“apple,banana,carrot”。

function SETADD(list, item) {
var array = list.split(',');
if (!array.includes(item)) {
return list + ',' + item;
}
else {
return list;
}
}

此函数返回一个错误 TypeError: Cannot find function includes in object apple,banana. (第 3 行)。 看起来函数的第一个参数不是字符串?我做错了什么?

最佳答案

不幸的是,在当前阶段,Array.includes() 还不能在 Google Apps 脚本中使用。那么作为解决方法,这个修改怎么样?

来自:

if (!array.includes(item)) {

收件人:

if (array.indexOf(item) === -1) {

引用资料:

关于javascript - 将项目添加到逗号分隔列表的自定义 Google 表格功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55966256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com