Javascript对日期对象数组进行排序
我有一个函数,它返回一个日期对象数组Javascript对日期对象数组进行排序,javascript,Javascript,我有一个函数,它返回一个日期对象数组 function get_location_dates(filter){ return filter.map(function(){ var [day, month, year] = $(this).text().split('-'); return new Date(parseInt(year), parseInt(month)-1, parseInt(day)); }).get(); }
function get_location_dates(filter){
return filter.map(function(){
var [day, month, year] = $(this).text().split('-');
return new Date(parseInt(year), parseInt(month)-1, parseInt(day));
}).get();
}
$('#dropoff-locations .date:first').text();
"25-09-2019"
var dropoff = $('#dropoff-locations .date');
undefined
get_location_dates(dropoff);
(2) [Wed Sep 25 2019 00:00:00 GMT+0300 (East Africa Time), Tue Sep 24 2019 00:00:00 GMT+0300 (East Africa Time)]
我现在需要将它们从最早的日期排序到最早/最晚的日期。
与包含日期的数组的列表不同,这纯粹是一个日期数组,因此不完全适用于这些场景
我该怎么做?这是我找到的解决方案
function get_location_dates(filter){
return filter.map(function(){
var [day, month, year] = $(this).text().split('-');
return new Date(parseInt(year), parseInt(month)-1, parseInt(day));
}).get().sort(function(a, b){
return a - b;
});;
}
你的问题是什么?你试过什么?