[英]How to skip current iteration of loop if condition is not met?
如果我想跳過
x.configured === true
是假的。 我的代碼(工作正常)
for (let i = 0; i < appids.length; i++) {
let appid = appids[i];
const endpointurl = baseurl + appid + '/branches'
setTimeout(() => {
fetch(endpointurl, {
headers: { Authorization: token }
}).then(response => response.json())
.then(data => {
if (Array.isArray(data)) {
console.log('appid ' + appid + ' has ' + data.filter(x => x.configured === true).length + ' configured branches');
}
});
}, i * 1000);
}
如果我想跳過
x => x.configured === false
問題是循環已經完成了工作。
如何重構它?
如果您想跳過一次迭代,請使用“繼續”關鍵字,如果您想停止循環,請使用“中斷”。 查看此頁面了解更多信息: https://www.w3schools.com/js/js_break.asp
但是在您的代碼中,您已經在過濾“x.configured === true”,“x => x.configured === false”已經被跳過
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.