Javascript examples for Statement:for
Omit the last parameter, and increment the values inside the loop:
<!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>