I'm currently working with Javascript and for now I'm searching a way to check if variable contains at least one string. I have looked at previous questions, however, neither contain what I'm looking for. I have a function here:
function findCertainWords()
{
var t = {Some text value};
if (t in {'one':'', 'two':''})
return alert("At least one string is found. Change them."), 0;
return 1
}
Variable a is user's written text (for example, a comment or a post).
I want to check if user has written certain word in it and return an alert message to remove/edit that word. While my written function works, it only works when user writes that word exactly as I write in my variable ("Three" != "three"
). I want to improve my funtion so it would also find case-insensitive ("Three" == "three"
) and part of words (like "thr" from "three"). I tried to put an expression like *
but it didn't work.
It would be the best if every expression could be written in one function. Otherwise, I might need help with combining two functions.