数字数组 - sort()

  1. <html>
  2. <body>
  3.  
  4. <script type="text/javascript">
  5.  
  6. function sortNumber(a, b)
  7. {
  8. return a - b
  9. }
  10.  
  11. var arr = new Array(6)
  12. arr[0] = "10"
  13. arr[1] = "5"
  14. arr[2] = "40"
  15. arr[3] = "25"
  16. arr[4] = "1000"
  17. arr[5] = "1"
  18.  
  19. document.write(arr + "<br />")
  20. document.write(arr.sort(sortNumber))
  21.  
  22. </script>
  23.  
  24. </body>
  25. </html>