This function will tell you if the substring is in the string and how many times.
const wordInText = (wordToFind, wholeText) => { const wordToFindRegex = new RegExp(wordToFind, 'gi'); const occurences = wholeText.match(wordToFindRegex) ?? []; return {isWordInText: occurences.length > 0, occurences: occurences.length}; } console.log(wordInText("is", "This cow jumped over this moon"))