Learn how to sort an array numerically in JavaScript.
You can use the folllowing to sort an array numerically:
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 descending:
const points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return b - a});
Try it Yourself »
Read more about how to sort arrays in our JavaScript Sorting Arrays Tutorial.
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!