Javascript examples for Statement:for
Initiate multiple values in the first parameter of for loop
<!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>