How to sort a numeric array

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});

Try It Yourself

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});

Try It Yourself

Related Pages

Tutorial:JavaScript Array Sorting