Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript对日期对象数组进行排序_Javascript - Fatal编程技术网

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;
        });;
}

你的问题是什么?你试过什么?