I was just testing the in operator in Javascript. When I run something like console.log("cookie" in document), it logs true, but when I do console.log("cookie" in "cookiejar") or assign cookiejar to a variable a and then do console.log("cookie" in a), I get an error statement TypeError: invalid ‘in’ operand a. Can anyone tell me why is it behaving like this?
I was just testing the in operator in Javascript. When I run something like
Share
The
inoperator doesn’t do what you think it does. ainb tells you if a given object b has the property named a.You cannot use
into search for characters in a string. UseindexOffor that.Note that the
inoperator is entirely separate from and completely unrelated to thefor-instatement.