在 for...of 循环中使用 switch 语句时,switch 中的 break 语句会终止当前的 switch 语句,而不会终止 for...of 循环。如果你想要终止 for...of 循环,你需要使用 break 语句,放在 for...of 循环外面,或者使用 return 语句。
示例代码:
for (const item of items) {
switch (item) {
case 'A':
console.log('Case A');
break;
case 'B':
console.log('Case B');
break;
default:
console.log('Default case');
}
}