JavaScript Code


How to check if strings are equal ignoring case using JavaScript?


Check if strings are equal ignoring case

Given two strings, check if the two strings are equal ignoring case using JavaScript.

Solution

To check if two strings are equal ignoring the case, we need to check if the lowercase version of the two strings are equal. We can also check if the uppercase versions of the two strings are equal.

Program

1. Given two strings are str1 and str2. Check if str1 and str2 are equal ignoring case.

let str1 = 'AppLE';
let str2 = 'apple';
if ( str1.toLowerCase() === str2.toLowerCase() ) {
    console.log('two strings are equal ignoring case');
} else {
    console.log('two strings are not equal ignoring case');
}