代码如下: var as = [1,2,11,3434,3,4545,33,55,0]; as.sort(); //这个排序是按照字典排序 //自定义按照数字排序 function sortByNum(a,b){ return parseInt(a) - parseInt(b); } as.sort(sortByNum); //按照对象来排序 //定义一个person对象 function Person(name.age){ this.name=name; this.age=age; } var p1 = new Person("zhang1",11); var p2 = new Person("zhang2",1); var p3 = new Person("zhang3",18); var p4 = new Person("zhang4",13); var ps = [p1,p2,p3,p4]; function sortByName(obj1,obj2){ if(obj1.name>obj2.name){return 1} else if(obj1.name==obj2.name){return 0} else{return -1} } function sortByAge(obj1,obj2){ return obj1.age - obj2.age; } ps.sort(sortByName) //按照名字排序 ps.sort(sortByAge) //按照年龄排序