javascript - Google App Script looping through array of values
问题描述
Hello I'm trying to loop through an array of values and If the any of the values is bigger than 0, then the script should send a specific email. I just cant figure it out how to do it. What am I doing wrong?
var TO = ['email1@gmail.com','email2@gmail.com'];
var failedOperation = [0, 0, 0, 52, 2, 5,]
var message1 = 'Check the sheet';
var message2 = 'Its Ok';
var subject = 'Your Google Spreadsheet Alert';
for(var i in failedOperation && var j in TO){
if(typeof failedOperation[i] > 0){
MailApp.sendEmail(TO[j], subject, message1);
}
else{
MailApp.sendEmail(TO[j], subject, message2);
}
}
解决方案
function www() {
var TO = ['email1@gmail.com','email2@gmail.com'];
var failedOperation = [0, 0, 0, 52, 2, 5];
var message1 = 'Check the sheet';
var message2 = 'Its Ok';
var subject = 'Your Google Spreadsheet Alert';
for(var i=0; i<failedOperation.length;i++){
if(failedOperation[i]>0){
MailApp.sendEmail(TO[1], subject, message1);
}else{
MailApp.sendEmail(TO[0], subject, message2);
}
}
}
推荐阅读
- excel - 自动过滤弄乱日期格式?
- javascript - 一个复选框中的两个值与反应
- c++ - C++11:将 POD 附加到 vector<> 的最有效方法
- python - 尝试添加分类值时,Pandas 错误“AttributeError:'DataFrame' 对象没有属性'add_categories'”?
- linux - Linux 是否支持不需要安装的独立软件包/软件?
- embedded - 为什么使用中断调用它
- r - 索引和聚合以搜索匹配值 Excel 版本到 R 版本
- python - ImportError: No module named PIL - 成功安装后出错
- python - 在getter方法中为dict赋值
- reactjs - 为 Govcloud 放大?