<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
function sortUp(a,b){
return a-b;
}
function sortDown(a,b){
return b-a;
}
var arr=new Array(6);
arr[0]=10;
arr[1]=5;
arr[2]=8;
arr[3]=30;
arr[4]=55;
arr[5]=32;
// 升序
document.write(arr.sort(sortUp));
// 5,8,10,30,32,55
//降序
document.write(arr.sort(sortDown));
// 55,32,30,10,8,5
</script>
</body>
</html>
原文:https://www.cnblogs.com/lxystar/p/10824446.html