jQuery find value inArray with case insensitive or ignore case

How to use jQuery inArray function with insensitive or ignore case option for finding value in array. Here find value in array with case insensitive comparison given in two ways. First is convert array value in lowercase and use inArray. Second is making loop on array and convert your needle value and array element value to lowercase and compare both value.

jQuery
jQuery

jQuery inArray with case insensitive or ignore case

When we use jQuery inArray function, it will return result with exact match. It means if array element or your search value have uppercase or lowercase difference, inArray function will return -1.

var myValue = 'veVlO.cOm';
var myArr = ['vevlo.COM', 'Google.com'];

//Convert value and array in lowercase
var lwrMyValue = myValue.toLowerCase();
var lwrMyArr = myArr.map(function(ele) { return ele.toLowerCase(); });

//User jQuery inArray
if($.inArray(lwrMyValue, lwrMyArr) != -1)
    alert('Value exist in array');
else
    alert('Value not exist in array');

Process complete in two step
1) First convert myValue and myArr in lowercase.
2) Use jQuery inArray() with lowercase array and value.

JavaScript find value in array with case insensitive or ignore case

This is second way to find value in array with case insensitive. In this case we make loop on array and convert needle value and array element value to lowercase and compare both values.

var myValue = 'veVlO.cOm';
var myArr = ['vevlo.COM', 'Google.com'];

if(existInArr(myValue, myArr))
    alert('Value exist in array');
else
    alert('Value not exist in array');

function existInArr(val, arr){
    var retVal = false;

    if(arr.length){
        for(var i=0; arr.length > i; i++ ){
            if(val.toLowerCase() == arr[i].toLowerCase()){
                retVal = true;
                break;
            }
        }
    }

    return retVal;
}