例如:将数组a内元素按照从大到小排列
var a = [100,2,54,7,45,6,10,8,9]; for(var i = 0; i <= a.length-1;i++){ for(j = i+1;j <= a.length;j++){ if(a[i]<a[j]){ var m =[]; m = a[i] ; a[i] = a[j] ; a[j] = m; } } document.write(a[i]+" "); }当然,数组中自带排序方法:js数组的sort排序详解
var a = [100,2,54,7,45,6,10,8,9]; for(var i = 0; i <= a.length-1;i++){ for(j = i+1;j <= a.length;j++){ if(a[i]<a[j]){ var m =[]; m = a[i] ; a[i] = a[j] ; a[j] = m; } } document.write(a[i]+" "); }当然,数组中自带排序方法:js数组的sort排序详解