我有一個帶有步驟的 For 回圈,如果變數中的值等于某個文本,我需要能夠跳過一個步驟。
例如 - 在下面的代碼中,如果 var airport 不等于 JFK,我想跳過第 0 步:
var airport = 'JFK';
for (let step = 0; step < 2; step ) {
rec.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: 1261,
forceSyncSourcing: true
})
)
uj5u.com熱心網友回復:
如果滿足條件,您希望使用條件陳述句 withcontinue來終止該特定迭代。
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue
下面的簡單作業片段。注意回圈 0 丟失。
var airport = 'JFK';
for (let step = 0; step < 4; step ) {
if (airport == 'JFK' && step==0) {continue}
// code;
// code;
console.log(`step ${step} executed`);
}
console.log("loop finished");
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/452791.html
標籤:javascript for循环
上一篇:對于多行(i 1)的函式?
