js數組按照兩個條件排序
妳好,這個問題我這樣解決的,妳看下:
var?arr=?[?{name:'qqq',?num:2,time:'2015-06-08?13:44:18'},?
{name:'www',?num:3,time:'2015-06-08?13:44:18'},?
{name:'eee',?num:4,time:'2015-06-07?13:40:18'},
{name:'rrr',?num:4,time:'2015-06-08?13:44:18'},?
{name:'yyy',?num:6,time:'2015-06-07?13:40:18'},?];
arr.sort(function(a,?b){
if?(a.num?===?b.num)?{
return?new?Date(b.time.replace(/-/g,?"/"))?-?new?Date(a.time.replace(/-/g,?"/"))
}?else?{
return?b.num?-?a.num;
}
});
console.log(arr);?//?yyy,rrr,eee,www,qqq
希望是妳想要的答案,望采納~~