javascript string includes case insensitive code example

Example 1: array contains case insensitive javascript

var array = ['I', 'hAve', 'theSe', 'ITEMs'],
    query = 'these',
    result = array.findIndex(item => query.toLowerCase() === item.toLowerCase());

console.log(result); // 2

Example 2: Javascript case insensitive string comparison

var name1 = "Taylor Johnson";
var name2 ="taylor johnson";

//convert to lowercase for case insensitive comparison
if(name1.toLowerCase() === name2.toLowerCase()){
    //names are the same
}

Example 3: javascript string search case insensitive

function stringContainsCaseInsensitive(search, subject){
    return subject.toLowerCase().indexOf(search.toLowerCase()) !== -1;
}

stringContainsCaseInsensitive("red","We painted the room red.");//true

Example 4: js includes case insensitive

var passedinstring = localStorage.getItem("passedinstring").toLowerCase();