<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> // 冒泡排序 var arr = [1,4,6,9,10,8,100,88]; var ln =arr.length; var t=0 for(var i=0;i<ln;i++){ for(var m=i+1; m<ln; m++){ t++ // console.log(arr[i],arr[m]) if(arr[i]>arr[m]){ var tmp=arr[m]; arr[m] = arr[i]; arr[i] = tmp; } } } console.log(arr,t,ln) </script> </body> </html>