How to make case insensetive in Javascript?
Question
There is an if statement as below.
1 | if (str.indexOf("Abc") == -1) { |
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 | if (str.toLowerCase().indexOf("Abc") == -1) { |
In this way, Abc will convert into abc.
Reference
This is the end of post