Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

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

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda