The break Statement
The break statement performs a forced
exit from a loop. It can terminate any loops:
for,
for-of,
for-in,
while.
Syntax
break;
Example
Let's determine if the array contains the number 3.
If it does - output '+++' to the console
and exit the loop:
let arr = [1, 2, 3, 4, 5];
for (let elem of arr) {
if (elem == 3) {
console.log('+++');
break; // exit the loop
}
}
See also
-
lesson from the JavaScript Tutorial,
which describes working withbreakin detail -
the
continuestatement,
which advances the loop to the next iteration