var arr = [2,10,6,9,7,8]; var arr1 = arr.sort(); var arr2 = arr.sort(function(a,b){ if (a>b){ return -1; }else if(a<b){ return 1 } }); alert(arr1);//10,9,8,7,6,2 alert(arr2);//10,9,8,7,6,2 alert(arr);//10,9,8,7,6,2
时间: 2024-10-12 21:48:05
var arr = [2,10,6,9,7,8]; var arr1 = arr.sort(); var arr2 = arr.sort(function(a,b){ if (a>b){ return -1; }else if(a<b){ return 1 } }); alert(arr1);//10,9,8,7,6,2 alert(arr2);//10,9,8,7,6,2 alert(arr);//10,9,8,7,6,2