数组排序
<!doctype html> <html> <head> <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"> <meta charset="utf-8"> <title></title> </head> <body> </body> <script> var arr = [1,52,65,25,12,35,1,2,2,4,5,53,3,4] for(var i=0;i<arr.length-1;i++){ for(var j=0;j<arr.length-1;j++){ var t; if(arr[j]>arr[j+1]){ t=arr[j]; arr[j]=arr[j+1]; arr[j+1]=t; } } } console.log(arr); var arr2 = [1,52,65,25,12,35,2,5,53,3,4] arr2.sort(function(d,b){ return d-b; }) console.log(arr); </script> </html>