Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

indexof case insensitive javascript

// First approach: convert all letters to either uppercase or lowercase
const favorite = "JavaScript";
const languages = "JavaScript, Python, and C#";
if (languages.toUpperCase().indexOf(favorite.toUpperCase()) !== -1) {
	console.log(`${favorite} is listed`);
} else {
  console.log(`${favorite} is not listed`);
}
// Alternatively, a regular expression can be used
const pattern = /Java/i; // i => ignore case flag
if(pattern.test(languages)) {
  console.log(`${favorite} is listed`);
} else {
console.log(`${favorite} is not listed`);
}
 
PREVIOUS NEXT
Tagged: #indexof #case #insensitive #javascript
ADD COMMENT
Topic
Name
2+4 =