数组sort.html
382 Bytes
<html>
<head>
</head>
<body>
<script>
var arr = ["10","5","40","25","1000","1"]
document.write(arr+"<br/>")
document.write(arr.sort()+"<br/>")
//从小到大
function sortNumber(a,b){
return a - b
}
document.write(arr.sort(sortNumber)+"<br/>")
//从大到小
function sortNumber2(a,b){
return b - a
}
document.write(arr.sort(sortNumber2)+"<br/>")
</script>
</body>
</html>