Prev Demo
Descending Order Sorting
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Descending order Sorting</h1> <p>Click the button to sort an array in Descending Order.</p> <button onclick="myFunction()">Click</button> <p id="myId"></p> <script> var a = [85, 52, 56, 98, 74, 32, 5, 9, 99]; document.getElementById("myId").innerHTML = a; function myFunction() { a.sort(function (a, b) { return b - a }); document.getElementById("myId").innerHTML = a; } </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output