Skip to content

JavaScript for of break | Example code

  • by

Using a break statement in for of loop will stop the current loop in JavaScript. The break statement to terminate a loop including for, while, and do…while prematurely.

Example of for of break JavaScript

Simple example code stop (exit) loop if element value is 1.

<!DOCTYPE html>
<html>
<head>

  <script>
    const array1 = [1, 2, 3];

    for (const element of array1) {
      console.log(element);

      if (element == 1);
        console.log("Break");
        break;
    }
  </script>

</head>
<body>

</body>
</html>

Output:

JavaScript for of break

Do comment if you have any doubts or suggestions on this Python for-of topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading