var temp;
var arr = [5,2,1,3,4];
for(var i=arr.length;i>0;i--){
for(var j = 0; j < i - 1; j++){
if(arr[j] > arr[j + 1]){
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1]=temp
}
}
}
console.log(arr);
//[1,2,3,4,5]
08-08
818
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-31
08-17
08-17