我有一个包含Unix时间戳的数组,我想对该数组进行排序,任何人都知道该怎么做?还是将其转换为简单的日期格式,然后以任何方式对它们进行排序?
也请举个例子
我已经尝试过了,但是没有用到Jquery-通过时间戳对数组进行排序的最快方法
我的代码:
//where rawutimes is unsorted unix time array
console.log(rawutimes);
// output ["1423857905", "1423611874", "1422953913", "1423499856", "1423502234", "1423502884", "1423503754", "1423510832", "1423511445", "1423514134", "1423358619", "1423583825", "1423713297", "1423713401", "1423735601", "1423772523", "1423768351", "1423817039", "1423166917", "1423446473", "1423446761", "1423835014", "1423858124", "1423857905", "1423855048", "1423852400", "1423852313", "1423852210", findIndex: function, find: function]
thesorted = rawutimes.sort(function(x, y){
return x.timestamp - y.timestamp;
});
//printing the sorted unix time array
console.log(thesorted);
//Output : ["1423857905", "1423852210", "1422953913", "1423499856", "1423502234", "1423502884", "1423503754", "1423510832", "1423511445", "1423514134", "1423358619", "1423583825", "1423713297", "1423713401", "1423611874", …Run Code Online (Sandbox Code Playgroud)