So I am trying to sort array of objects by date but I want objects with dates to be priority over objects with null dates.
Example of non sorted array:
[
{due_date: null},
{due_date: '03/11/2020'},
{due_date: '02/10/2020'}
]
And I would like the the array to be in this order once sorted
[
{due_date: '02/10/2020'},
{due_date: '03/11/2020'},
{due_date: null}
]
However when I run the array through my script
var firstSort = 'due_date'
return array.sort((a, b) => {
return new Date(a[this.firstSort]) - new Date(b[this.firstSort])
})
I get this result
[
{due_date: null},
{due_date: '02/10/2020'},
{due_date: '03/11/2020'}
]
How can I compare a null date or exclude it when sorting?