How do I perform a JavaScript ignore case string comparison?

Greeting! I may be the last to answer but I surely won’t disappoint. I will keep it simple. Use String.prototype.toUpperCase() Similar to toLowerCase(), you can convert both strings to uppercase using toUpperCase(). The comparison will then be case-insensitive.

javascript Copy Edit

let str1 = "Hello";
let str2 = "HELLO";

if (str1.toUpperCase() === str2.toUpperCase()) {
console.log("The strings are equal (case-insensitive).");
} else {
console.log("The strings are not equal.");
}

toUpperCase() works the same way as toLowerCase() but converts the strings to uppercase before comparison.