Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda