<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body></body>
<script>
//数字排序(数字降序):
myFunction();
function myFunction() {
var points = [40, 100, 1, 5, 25, 10];
points.sort(function (a, b) {
return b - a;
});
//由a到b是从小到大,由b到a是从大到小
document.write(points);
} //页面显示==>>100,40,25,10,5,1
</script>
</html>
运行结果