Throughout javascript make array indexof case insensitive example tutorial you will learn how to make Array.indexOf() to case insensitive in JavaScript;
We can use the Array.findIndex method with convert the array element and the string to lowercase. This methods returns the element’s index or -1 if no elements satisfy the condition
Example 1:
const arr = ['CODING', 'DRIVER'];
const str = 'master';
const index = arr.findIndex(element => {
return element.toLowerCase() === str.toLowerCase();
});
console.log(index); // 1
if (index !== -1) {
// string is in the array
}
Example 2:
var array = [ 'I', 'LoVe', 'JavaScript', 'vErY', 'MuCh' ];
var query = 'JavaScript'.toLowerCase();
var index = -1;
array.some(function(element, i) {
if (query === element.toLowerCase()) {
index = i;
return true;
}
});
console.log(index); //Result: index = 2
I hope these examples help you.