Javascript examples for Array:sort
Sort an array alphabetically, and then reverse the order of the sorted items (descending):
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> var fruits = ["a","b","c","d","e"]; document.getElementById("demo").innerHTML = fruits; function myFunction() {/* ww w . java 2 s.c om*/ fruits.sort(); fruits.reverse(); document.getElementById("demo").innerHTML = fruits; } </script> </body> </html>