for…of循环
for...of
循环的编写方式和 for...in
循环的基本一样,只是将 in
替换为 of
,可以忽略索引。
for...of
解决了 for 和 for…in 循环的不足之处。你可以随时停止或退出 for…of 循环
const digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
for (const digit of digits) {
if (digit % 2 === 0) {
continue;
}
console.log(digit);
}