Murali P

Murali P

  • 1.5k
  • 190
  • 16.5k

Regarding the string comparison irrespective of case type

Oct 16 2023 10:45 AM

hi friends,

i would like to compare the strings irrespective of case type. so written the code like below.

var str1 =" HelloWorldlookatme";

var str2 = "world";

var compare1 = ((str1 !== undefined && str1 !== "") ? str1.toUpperCase() : "");

var compare2= ((str2 !== undefined && str2 !== "") ? str2.toUpperCase() : "");

var isContains = (compare1 .includes(compare2) && compare2.includes(compare1));

here if str1 is  "HelloWorldlookatme" and str2  is "world" then its working but viceversa not working..

do we need to keep OR condtion instead of AND
 

if (isContains)

{alert("Exists");}

else

{ alert("NonExists");

}

followed above code.. still any other way to do..kindly let me know

thanks in advance


Answers (3)