How to perform a case-insensitive search in Node.js

2 Answers

0 votes
function containsIgnoreCase(str, toFind) {
    return str.toLowerCase().indexOf(toFind.toLowerCase()) >= 0;
}
 
const str = "The FOX Profession is Node.js Programmer";
const toFind = "fox";
 
const contains = containsIgnoreCase(str, toFind);
 
console.log(contains);
 
 
    
/*
run:
    
true
   
*/
 

 



answered Feb 24, 2025 by avibootz
0 votes
function containsIgnoreCase(str, toFind) {
    const regex = new RegExp(toFind, "i");
     
    return regex.test(str)
}
 
const str = "The FOX Profession is Node.js Programmer";
const toFind = "fox";
 
console.log(containsIgnoreCase(str, toFind));
 
 
 
    
/*
run:
    
true
   
*/
 

 



answered Feb 24, 2025 by avibootz

Related questions

1 answer 83 views
1 answer 77 views
1 answer 93 views
1 answer 94 views
1 answer 95 views
1 answer 152 views
1 answer 72 views
...