数组的升降序排列
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>排列</title> </head> <body> <script type="text/javascript"> var arr = [1,10,30,2,3,5,100,500,200]; function ascending(i,j) { return i-j; } function descending(i,j){ return j-i; } alert(arr.sort(ascending)); alert(arr.sort(descending)); </script> </body> </html>