while Loop through the indices of an array to collect the car names from the cars array: - Javascript Statement

Javascript examples for Statement:while

Description

while Loop through the indices of an array to collect the car names from the cars array:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

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

<script>
function myFunction() {//  ww w.ja v a  2s. c  om
    var cars = ["a","b","c","d","e"];
    var text = "";
    var len = cars.length;
    while (len--) {
        text += cars[len] + "<br>";
    }
    document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>

Related Tutorials