Prev Demo
Reversing The Sort Order In An Array
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Reversing the sort order</h1> <p>Click the button to reverse the sort.</p> <button onclick="myFunction()">Click</button> <p id="myId"></p> <script> var a = ["India", "Pakisthan", "Bangladesh", "China"]; document.getElementById("myId").innerHTML = a; function myFunction() { a.sort(); //* Sort an array *// a.reverse(); //* Revsre the sorted array *// document.getElementById("myId").innerHTML = a; } </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output