In Javascript, when required you can stop or come out from the loop by placing break statement in the Javascript Loop Control.
The break statement is used to come out or stop the loop.
Syntax
Note: The <= could be anything that would fit the purpose ex. >, == or whatever.