Home > Software design >  Values Identical but not equal
Values Identical but not equal

Time:12-10

I 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?

CodePudding user response:

How do you fill dateList array?

CodePudding user response:

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.

  • Related