So, basically I'm working with string manipulation for a chatbot. When it returns a string from a message, I'm just checking if there's an specific word on it:
let msg = 'how are you?' //Message example
let words = msg.split(' ') //Words spliting
if ('are' in words) {} //This is where I'm having the problem
I know that in works for when I check a number inside of an array, but it doesn't seem to work with strings. Is there a different way to call it when it's about strings? I could do the checking using a loop, then a if (words[i] === 'are') {}, but I'd like to avoid that, if possible.
inoperator.inoperator.inworks for when I check a number inside of an array" It doesn't.inoperator checks if the object has the given key. You are probably doing something likeif(1 in [1,2,3]). It returns true because the array has the key1. If you doif (1 in [2,3,4]), that ALSO returns true because it doesn't check the value, but the keys of the array.