Use a double/triple comparison operator in the IF statement ==
or ===
<script>
for ( var i = 0; i < 10 ; i++ ) {
console.log(i);
if ( i == 5 ) {
console.log (i);
break;
}
}
</script>
Also, this will output 0 1 2 3 4 5 5
. If you want the output to be 0 1 2 3 4
, you should use the following code in place of the current IF
statement.
if ( i == 4 ) {
break;
}