Javascript examples for Array:sort
Sort numbers in an array in ascending order:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> var points = [40, 100, 1, 5, 25, 10,123,321,12]; document.getElementById("demo").innerHTML = points; function myFunction() {//from www. jav a 2 s . co m points.sort(function(a, b){return a-b}); document.getElementById("demo").innerHTML = points; } </script> </body> </html>