<title>数组排序(冒泡排序)</title>
<script>
var arr = [5, 7, 2, 1, 3, 9];
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr.length - i; j++) {
if (arr[j] > arr[j + 1]) {
// 从小到大递增
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
console.log(arr);
</script>
实现效果: