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