根据对象的某个属性名的值从新排序
var list=[ { name:"aaa", score:80 }, { name:"bbb", score:70 }, { name:"ccc", score:90 }, { name:"ddd", score:60 } ]; function compareFn(propertyName){ return function(obj1,obj2){ var value1 = obj1[propertyName]; var value2 = obj2[propertyName]; if(value1 < value2){ //return 1 //max-min return -1 //min-max }else if(value1 > value2){ //return -1;//max-min return 1;// min-max }else{ return 0; } } } list.sort(compareFn('score'));//-1,从min-max排序,1 从max-min
-----------------------------------------------------------------------小二给我来二两轮子!