Suppose there are five words (substring) cat, dog, elephant, tiger, lion and there is a sentence string -- > "We have one cat in our home". Now i need to see which of the substring is present in the string.
So how can we use string.include(substring) to check if any of the substring in present in string and if true which substring is it.
You can store the words to find in an array and use Array.filter to filter out the items that aren't included in the string.
const wordsToFind = ['cat', 'dog', 'elephant', 'tiger', 'lion']
const string = "We have one cat in our home";
const includedWords = wordsToFind.filter(e => string.includes(e))
const doesInclude = includedWords.length != 0;
console.log('Does include? ', doesInclude)
console.log('Included words: ', includedWords)