gpt4 book ai didi

javascript - 该脚本工作正常,但不在 'google-apps-script' 中

转载 作者:行者123 更新时间:2023-11-28 14:43:50 25 4
gpt4 key购买 nike

function main() {

var data = [['test1', 'element1', 'price1'], ['', 'element2', 'price2'], ['', 'element3', 'price3'], ['','' ,'' ], ['test2', 'anotherele1', 'anotherprice1'], ['', 'anotherele2', 'anotherprice2'], ['', 'anotherele3', 'anotherprice3'], ['', '', ''], ['test3', 'aaa', 123.0], ['', 'bbb', 345.0], ['', 'ccc', 678.0], ['', '', ''], ['','' , '']]

var test = parseData(data)
Logger.log(test)
}


function isBlank(line) {
return line[0].trim() === '' && line[1].trim() === '';
}


function parseData(data) {

const output = {};
let currentGroupName = '';

data.forEach(line => {
if (isBlank(line)){
return;
}

if (line[0].trim().length > 0) {
currentGroupName = line[0].trim();
}

output[currentGroupName] = output[currentGroupName] || {};

output[currentGroupName][line[1]] = line[2];
});

return output;
}

每当我在计算机上运行以下 JS 脚本时,它都可以正常工作。但是,如果我尝试在 Adwords 上以 Preview(类似 Adwords 控制台)的形式运行,则会出现合成错误 Syntax Errors in script: Missing ;在声明之前。 (第 23 行)。请注意,第 23 行只是 let currentGroupName = '';。有没有一种干净的方法来解决这个问题?此代码适合在您自己的计算机上以及使用 google-apps-scripts 进行测试。

这是我的问题的图片:

enter image description here

最佳答案

田池的解决方案应该可以解决您的问题。但请允许我添加一些更多的背景信息。 Google Apps 脚本自 2009 年以来一直存在,它是 Ecmascript 5 的实现。let 语句和箭头运算符仅在 Ecmascript 6 及更高版本中受支持。

Google 问题跟踪器上有一个要求 App 脚本支持 EcmaScript 6 的功能请求。 Apps 脚本社区中的许多人一直在呼吁支持 Ecmascript 6。您可以通过给问题加注星标来表达您的声音。

这是它的链接: https://issuetracker.google.com/issues/36764074

关于javascript - 该脚本工作正常,但不在 'google-apps-script' 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47190499/

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