This is hard to explain so I'll just show an example. I have an array of specific keywords, like so:
const keywordArr = ['jim', 'john'];
then I have a string:
const message = 'Hello john, how are you doing today?'
I would like to check if message
contains a value from keywordArr
. I know I could loop through each value in keywordArr
and check like this:
keywordArr.forEach(function(word) {
if (message.toLowerCase().includes(word)) {
rest of code here..
}
}
However, I get around 5 messages each second, so that method would be very performance consuming. Is there any efficient way to do this?