I'm trying to check whether an array, called ruleFolderNames, contains a string, using the .includes() Javascript method. The string I am checking is "Centers For Medicare & Medicaid Services".
ruleFolderNames.includes("Centers For Medicare & Medicaid Services"); // true
However, I'm not typing the string directly, I'm using a variable (called department). I've found that the department variable is not equal to the first item in the array, Centers For Medicare & Medicaid Services, even though they appear to be the same.
Here are the console.log statements:
ruleFolderNames[0]; // Centers For Medicare & Medicaid Services
typeof ruleFolderNames[0]; // string
department; // Centers For Medicare & Medicaid Services
typeof department; // string
But in fact, the variable department is not equal to the string I'm searching for.
department == "Centers For Medicare & Medicaid Services" // OUTPUTS FALSE!!!
I've included the link to my full Github repository if that's useful, the bug is contained on line 36 of this file.
.lengthof each string, and if that doesn't pan out, compare the charCodes of each string.for (const letter of department) console.log(letter.charCodeAt(0));Find the first that doesn't match (or use aforloop and do something whendepartment[i] !== ruleFolderNames[0][i])