Question

There is an if statement as below.

1
2
3
if (str.indexOf("Abc") == -1) {
console.log("pass");
}

I want to make Abc case insensitive, so Abc, abc, ABc etc will still pass through.

Answer

Add .toLowerCase() after str. This method will make all letters to lower case.

1
2
3
if (str.toLowerCase().indexOf("Abc") == -1) {
console.log("pass");
}

In this way, Abc will convert into abc.

Reference


This is the end of post