gpt4 book ai didi

google-apps-script - 如何使用 getLabel() 正确编写以下 if 语句

转载 作者:行者123 更新时间:2023-12-01 13:39:41 25 4
gpt4 key购买 nike

我收到以下错误,想知道如何正确重写这段代码。

ReferenceError: Function function getLabel() {/* */} can not be used as the left-hand side of assignment or as an operand of ++ or -- operator. (line 61, file "DLContactsToSheet")

    var Phones = "";    
for ( var g=0;g<contacts[i].getPhones().length;g++)
{
if (contacts[i].getPhones()[g].getLabel() = "MOBILE_PHONE") {
Phones += "C: "
} else if (contacts[i].getPhones()[g].getLabel() = "WORK_PHONE") {
Phones += "W: "
} else if (contacts[i].getPhones()[g].getLabel() = "HOME_PHONE") {
Phones += "H: "
} else {
Phones += "O: "
}
Phones += contacts[i].getPhones()[g].getPhoneNumber();
Phones += "\n";
}
try{ContactArray.push(Phones);}
catch(e){ContactArray.push("N/A")}

最佳答案

在您的条件中,引用错误似乎是由“=”而不是“==”引起的。

将条件重写为 if (phone.getLabel() == 'MOBILE_PHONE') {/* ... */} 等应该可以解决问题。

关于google-apps-script - 如何使用 getLabel() 正确编写以下 if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41309339/

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