Regular break only exits the innermost loop. To exit outer loops, use labels:
outer: for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
if (i === 1 && j === 1) {
break outer // Exits both loops
}
console.log(i, j)
}
}
Labels are rarely needed. Usually you can restructure code or use a function with return instead.