var arr = [5,1,4,85,25,252]; arr.sort(function(a,b){ return b-a; //从大到小降序 }) console.log(arr) // [252, 85, 25, 5, 4, 1] var arr = [5,1,4,85,25,252]; arr.sort(function(a,b){ return a-b; //从小到大升序 }) console.log(arr) //[1, 4, 5, 25, 85, 252]
var arr = [5,1,4,85,25,252]; arr.sort(function(a,b){ return b-a; //从大到小降序 }) console.log(arr) // [252, 85, 25, 5, 4, 1] var arr = [5,1,4,85,25,252]; arr.sort(function(a,b){ return a-b; //从小到大升序 }) console.log(arr) //[1, 4, 5, 25, 85, 252]