var arr = [5, 1, 3, 2, 6, 4];

for(var j = 0; j < arr.length - 1; j++) {
  for(var i = j + 1; i < arr.length; i++) {
   if(arr[j] > arr[i]) {
    var temp = arr[j];                                                   //交换数据位置
    arr[j] = arr[i];
    arr[i] = temp;
   }
  }
 }
 for(var x in arr) {
  document.write(arr[x] + "&nbsp;&nbsp;")                      //输出数组
 }