How TO - Sort Numeric Array
Learn how to sort an array numerically in JavaScript.
Sort an Array Numerically
You can use the folllowing to sort an array numerically:
Example
const points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return a - b});
Try it Yourself »
points.sort(function(a, b){return a - b});
You can also sort the array descending:
Example
const points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return b - a});
Try it Yourself »
points.sort(function(a, b){return b - a});
Read more about how to sort arrays in our JavaScript Sorting Arrays Tutorial.