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

173
Vistas
Values Identical but not equal

Image of my array valuesI have a function to "Wed 12/8" and "Wed 12/8". However, when I use them in this function they are not equal for some reason yet they are identical. The function does not append and acts as if they are completely different.

function filterDate() {
  for (var i = 0; i < dateList.length; i++) {
    if(dateList[i] == today) {
      appendItem(filteredDate, dateList[i]);
      appendItem(filteredID, stateID[i]);
      appendItem(filteredCase, totalCases[i]);
      appendItem(filteredState, usState[i]);
    }
  }
}

Here the get date code.

//Date
var now = new Date();

//Gets the current days date
var days = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
var months = ['1','2','3','4','5','6','7','8','9','10','11','12'];
var weekday = days[now.getDay() - 1];
var day = now.getDate() - 1;
var month = months[now.getMonth()];
var today = weekday + " " + month + "/" + day;

//Console logs todays date
console.log(today);

The values are the exact same but the computer thinks they are not. When I manually change today to "Wed 12/8" it works but the variable seems to mess it up though I may be wrong. What's happening and how do I fix this as it is crucial to my program?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem should be the way you populate the dateList array. Are you sure it gets filled with strings too, and not for example date objects? The code you provided does not show anything related to that array.

Edit: Based on the image you provided later, I think the issue will be that your strings in the array contain quotation marks.

Remove them from the strings. (For example by slicing the first and last characters from it in the filterDate function)

function filterDate() {
  for (var i = 0; i < dateList.length; i++) {
    if(dateList[i].slice(1,-1) == today) {
      appendItem(filteredDate, dateList[i]);
      appendItem(filteredID, stateID[i]);
      appendItem(filteredCase, totalCases[i]);
      appendItem(filteredState, usState[i]);
    }
  }
}
about 4 years ago · Juan Pablo Isaza Denunciar
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