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

javascriptbreak;

Example

Let's determine if the array contains the number 3. If it does - output '+++' to the console and exit the loop:

javascriptlet arr = [1, 2, 3, 4, 5];

for (let elem of arr) {
  if (elem == 3) {
    console.log('+++');
    break; // exit the loop
  }
}

See also