<script type="text/javascript"> var sdts = [ {name:"小明",age:30}, {name:"小红",age:20}, {name:"小花",age:40} ] function compare(property,desc) { return function (a, b) { var value1 = a[property]; var value2 = b[pro
我这里是根据次数进行倒叙,可根据自己情况进行修改 function sortKey(array,key){ return array.sort(function(a,b){ var x = a[key]; var y = b[key]; return ((x>y)?-1:(x<y)?1:0) }) };
js sort方法根据数组中对象的某一个属性值进行排序 sort方法接收一个函数作为参数,这里嵌套一层函数用来接收对象属性名,其他部分代码与正常使用sort方法相同. var arr = [ {name:'zopp',age:0}, {name:'gpp',age:18}, {name:'yjj',age:8} ]; function compare(property){ return function(a,b){ var value1 = a[property]; var value2 = b