• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

155
Views
Can i force empty date object to be reassigned?

I am doing a to-do list, everything else works fine, but there's one issue that keeps bothering me. Since I don't want to set the date and the time as required input, so sometimes the date and time will be left blanket. But when I sorted the date ascending, the empty date's row will just pop up to the top. I hope it always is put to the bottom, no matter how I sort it. I tried to reassign the date to '2100-11-30T00:00:00'before compare function, but it's not working, and the console shows "Invalid Date". So I just wondering if there's any way to fix it? or Any solution to solve this problem?

const dateDown = document.querySelector(".dateDown")
dateDown.addEventListener("click", () => {

    let arrayList = JSON.parse(localStorage.getItem("theList"));
    arrayList.sort(function (a, b) {
        let aDate = new Date(a.date) + a.time;
        let bDate = new Date(b.date) + b.time;

        if (aDate === null) {
            aDate = new Date('2100-11-30T00:00:00');
        }
        console.log(aDate, bDate);
        if (aDate < bDate) {
            return 1;
        } else if (aDate > bDate) {
            return -1;
        } else if (aDate == bDate) {
            return 0;
        }
    })

almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error