var aa=[{"time":Date.parse("2017/02/22 16:30"),"val":22},{"time":Date.parse("2017/02/21 16:30"),"val":11},{"time":Date.parse("2017/02/23 16:30"),"val":33},{"time":Date.parse("2017/02/24 16:30"),"val":44}]如上代码,在javascript里,我想把日期按21,22,23,24日排序,该用什么算法呢?谢谢
1 回答
蛊毒传说
TA贡献1895条经验 获得超3个赞
直接用sort排序就可以吧
var aa=[
{"time":Date.parse("2017/02/22 16:30"),"val":22},
{"time":Date.parse("2017/02/21 16:30"),"val":11},
{"time":Date.parse("2017/02/23 16:30"),"val":33},
{"time":Date.parse("2017/02/24 16:30"),"val":44}
]
console.log('排序前:');
console.log(aa);
aa.sort(function(i1,i2){
return i1.time-i2.time;
});
console.log('排序后:');
console.log(aa);
添加回答
举报
0/150
提交
取消