var obj = [{
id : 1,
age : 20,
top :5
},{
id : 3,
age : 21,
top : 6
},{
id : 2,
age : 20,
top : 8
}]
function keysort(property) {
return function(a, b) {
var value1 = a[property] == '-' ? 0 : a[property];
var value2 = b[property] == '-' ? 0 : b[property];
return value1 - value2;
}
}
var obj1 = obj.sort(keysort('age'));
写一半 不会写了 age相同的情况下 再按照top从高到低排序 想请教下老司机
This is so long-winded...
Isn’t this great?
Just use what you bring
Because you are talking about sorting top from high to low. This way of writing means that the larger the number, the higher it is. If you want the smaller number to be smaller, just change the position b.top - a.top to a.top - b.top
Online experience https://jsfiddle.net/hguyjgs8/1/
https://jsfiddle.net/sojxjqpf/
Who First
Next
S
WhoFirst 升序。