Javascript examples for Statement:for
Loop through the indices of an array
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/* w ww. j a v a 2 s. c o m*/ var cars = ["a","b","c","d","e"]; var text = ""; var i; for (i = 0; i < cars.length; i++) { text += cars[i] + "<br>"; } document.getElementById("demo").innerHTML = text; } </script> </body> </html>