sortArrayDate(arrayToSort, arrayDateKey, order) {
if (order === 'ascending') {
arrayToSort.sort(function(a, b){
if (a[arrayDateKey] === '' || a[arrayDateKey] === null) {
return 1;
}
if (b[arrayDateKey] === '' || b[arrayDateKey] === null) {
return -1;
}
return new Date(a[arrayDateKey]).getTime() - new Date(b[arrayDateKey]).getTime();
});
} else {
arrayToSort.sort(function(a, b){
if (a[arrayDateKey] === '' || a[arrayDateKey] === null) {
return 1;
}
if (b[arrayDateKey] === '' || b[arrayDateKey] === null) {
return -1;
}
return new Date(b[arrayDateKey]).getTime() - new Date(a[arrayDateKey]).getTime();
});
}
}
I encountered an error at the specified line. Can anyone help me identify what is wrong with this code? The aim is to sort dates within an array.