替换foreach google脚本
我想为我替换foreach函数,以打破代码,以防我没有订单的客户。
当前代码:
customers.forEach(function (customer)
{
ss.toast(`Creating Invoice for ${customer.name}`, APP_TITLE, 1);
let invoice = createInvoiceForCustomer(
customer, products, transactions, invoiceTemplateSheet, ss.getId());
invoices.push(invoice);
});
我要制作的代码:
for (var i=1 ; i<=custlastrow ; i++)
{
if (customers.ordenes == "No")
{
continue; // Skip current iteration...
}
do the other part
}
I want to replace the forEach function for me to break the code in case i don't have a customer with an order.
Current code:
customers.forEach(function (customer)
{
ss.toast(`Creating Invoice for ${customer.name}`, APP_TITLE, 1);
let invoice = createInvoiceForCustomer(
customer, products, transactions, invoiceTemplateSheet, ss.getId());
invoices.push(invoice);
});
Code I'm trying to make:
for (var i=1 ; i<=custlastrow ; i++)
{
if (customers.ordenes == "No")
{
continue; // Skip current iteration...
}
do the other part
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了使生活更轻松,您可以在之前添加过滤器,这意味着您可以将
foreach
留下。这样:
我发现在循环中使用
继续
可能会导致凌乱的代码。 IMO以上更容易阅读。To make life easier, you could add a filter before, meaning you can leave the
forEach
.Like this:
I find that using
continue
in loops can lead to messy code. IMO the above is easier to read.