html - javascript array order value from big to small -


i new learning javascript , learn http://www.w3schools.com. want ask array in javascript. try code website.

try it

<script> function myfunction() {     var index;     var text = "<ul>";     var fruits = ["banana", "orange", "apple", "mango"];     (index = 0; index < fruits.length; index++) {         text += "<li>" + fruits[index] + "</li>";     }     text += "</ul>";     document.getelementbyid("demo").innerhtml = text; } </script> 

and result :banana,orange,apple,mango.

and want ask is, how change value result can : mango, apple, orange, banana? .i confused make "for" condition. thank guys. still beginner programming.

just iterate end start:

<script> function myfunction() {     var index;     var text = "<ul>";     var fruits = ["banana", "orange", "apple", "mango"];     (index = fruits.length-1; index >= 0; index--) {         text += "<li>" + fruits[index] + "</li>";     }     text += "</ul>";     document.getelementbyid("demo").innerhtml = text; } </script> 

Comments