How to check whether a user string contains any forbidden words from a list in TypeScript

1 Answer

0 votes
const forbidden = ["badword", "evil", "kill", "nasty", "terrible"] as const;
const text = "This text contains a badword inside";

const lower: string = text.toLowerCase();

if (forbidden.some(w => lower.includes(w))) {
  console.log("Forbidden word detected");
} else {
  console.log("No forbidden words found");
}

 
 
    
/*
run:
    
"Forbidden word detected" 
    
*/

 



answered Dec 27, 2025 by avibootz

Related questions

...