Omit the last parameter, and increment the values inside the loop: - Javascript Statement

Javascript examples for Statement:for

Description

Omit the last parameter, and increment the values inside the loop:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

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

<script>
function myFunction() {// w  w  w.  ja  va 2  s.  c o  m
    var cars = ["a","b","c","d","e"];

    var i = 0;
    var len = cars.length;
    var text = "";

    for (; i < len;) {
        text += cars[i] + "<br>";
        i++;
    }
    document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>

Related Tutorials