Prev Demo
Ascending Order Sorting
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Ascending order sorting</h1> <p>Click the button to sort an array in Ascending 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 a - b }); //* Ascending order is default in sorting method, we can use directly a.sort() *// document.getElementById("myId").innerHTML = a; } </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output