- /*
- 降序
- **/
- var test = [5,34,87,32,56,2,17];
- test.sort(function(a,b){
- return b-a;
- });
- console.log(test);
- /**
- 升序
- */
- var arr = [23,54,3,12,78];
- var result = arr.sort(function(a,b){
- return a-b;
- });
- console.log(result);
- //该片段来自于http://www.codesnippet.cn/detail/1903201511897.html
来源: http://www.codesnippet.cn/detail/1903201511897.html