JS Numeric Sort
Descending order and Ascending order
<!DOCTYPE html>
<html>
<body>
<p>Descending order <br><span id="demo1"></span></p>
<p>Ascending order <br><span id="demo2"></span></p>
<script>
// array
var points = [40, 90, 100, 80, 1, 10, 20, 30, 50, 60, 70,];
//sort the array in descending order
points.sort(function(a, b){return b - a}); // see b - a !
document.getElementById("demo1").innerHTML = points;
// sort the array in ascending order
points.sort(function(a, b){return a - b}); // see a - b !
document.getElementById("demo2").innerHTML = points;
</script>
</body>
</html
18 Related pages
- Date and Time JavaScript
- Display Date, JavaScripts
- Display Date, JS
- External JavaScripts in HTML head
- JavaScript confirm OK and Cancel
- JavaScript Promise API
- JavaScript redirect to
- JavaScript toggle class
- JS alert in php
- JS Blinking Text
- JS Date
- JS display image preview on the form before submit
- JS image inside ul li
- JS Numeric Sort
- JS prevent form resubmission
- JS, pop( ) remove last element in the array
- JS, push() adds to the last element in the array
- Timeout JS























