break statement
The break command performs a forced
loop termination. It can break any loop:
for,
for-of,
for-in,
while.
Syntax
break;
Example
Let's determine if an array contains
the number 3. If there is,
output the phrase 'it's here' to
the console and exit a loop:
let arr = [1, 2, 3, 4, 5];
for (let elem of arr) {
if (elem == 3) {
console.log('it's here');
break; // exits a loop
}
}
See also
-
the lesson from JavaScript tutorial
detailing how to work withbreak -
the
continuestatement
that moves a loop to next iteration