Omit the first parameter in for loop and set values before the loop starts - Javascript Statement

Javascript examples for Statement:for

Description

Omit the first parameter in for loop and set values before the loop starts

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. ja  v  a 2 s .  co m*/
    var cars = ["a","b","c","d","e"];
    var i = 2;
    var len = cars.length;
    var text = "";

    for (; i < len; i++) {
        text += cars[i] + "<br>";
    }

    document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>

Related Tutorials