1, the sort () method, I like the simple violence.
var arr = [21,100,-6,99,1] function sortNum(a,b){ return a-b; } arr.sort(sortNum);
console.log(arr);
2, ordinary bubble sort method, compared to the original easy to understand.
var arr = [210,100,6,99,1,12]; var timeData; for(var i in arr){ for(var y in arr){ if(arr[i]<arr[y]){ times = arr[i]; arr[i] = arr[y]; arr[y] = times; } } } console.log(arr);
biy1314.taobao.com