Currently, I am focused on string manipulation for a chatbot. My main objective is to identify a specific word within a returned string message. Here is an example of my approach:
let msg = 'how are you?' //An illustration of a message
let words = msg.split(' ') //Splitting the words
if ('are' in words) {} //Encountering an issue here
I understand that the in
operator is typically used to check for the presence of a number within an array, but it seems to be ineffective for string evaluation. Is there an alternative method to use when dealing with strings? While I could use a loop and an if (words[i] === 'are') {}
for checking, I prefer to explore alternative solutions if available.