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](https://i0.wp.com/tutorial.eyehunts.com/wp-content/uploads/2022/01/JavaScript-break-for-loop-1.jpg?resize=163%2C151&ssl=1)
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