js数组里是对象,那么怎么把里面的对象排序一下呢?

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日排序,该用什么算法呢?谢谢

ibeautiful
浏览 653回答 1
1回答

蛊毒传说

直接用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);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript