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
希望是你想要的答案,望采纳~~