冒泡排序
var arr=[10,50,30,40,60,70,100,20,30]; for(var i=0;i<arr.length-1;i++){ var bool=true; for(var j=0;j<arr.length-1-i;j++){ if(arr[j]>arr[j+1]){ var temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp; bool=false; } } if(bool){ break; } } document.write(arr); //10,20,30,30,40,50,60,70,100