为数组排序:sort()&reverse()
//sort() 方法是按照字典顺序对元素进行排序的 var num1 = [ 3, 1, 2, 100, 4, 200 ]; num1.sort(); alert(num1);//1,100,2,200,3,4 function compare(a, b) { return a - b;//升序 //return b - a;//降序 } var num = [ 3, 1, 2, 100, 4, 200 ]; num.sort(compare); alert(num); // 1,2,3,4,100,200
var a = [ 1, 2, 3, 4, 5 ]; a.reverse();//翻转 alert(a); // 5,4,3,2,1