How to sort a numeric array
- Previous Page JS Random Number
- Next Page JS Spread Operator
Learn how to sort arrays numerically in JavaScript.
Sort the array in numerical order
You can use the following methods to sort the array numerically:
Example
const points = [40, 100, 1, 5, 25, 10]; points.sort(function(a, b){return a - b});
You can also sort the array in descending order:
Example
const points = [40, 100, 1, 5, 25, 10]; points.sort(function(a, b){return b - a});
Related Pages
Tutorial:JavaScript Array Sorting
- Previous Page JS Random Number
- Next Page JS Spread Operator