Initiate multiple values in the first parameter of for loop - Javascript Statement

Javascript examples for Statement:for

Description

Initiate multiple values in the first parameter of for 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() {//from   ww w .  j  a v a 2 s.c  om
    var cars = ["a","b","c","d","e"];
    var i;
    for (i = 0, len = cars.length, text = ""; i < len; i++) {
        text += cars[i] + "<br>";
    }
    document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>

Related Tutorials