Use a for loop together with the continue statement. - Javascript Statement

Javascript examples for Statement:for

Description

Use a for loop together with the continue statement.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   w ww  . jav a 2  s.c om*/
    var cars = ["a","b","c","d","e"];
    var text = ""
    var i;
    for (i = 0; i < cars.length; i++) {
        if (cars[i] === "Saab") {
            continue;
        }
        text += cars[i] + "<br>";
    }
    document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>

Related Tutorials