M
Morgan
Hi all,
I was messing around with someone elses script when I noticed that he
had used the in keyword in an if conditional to compare a string with a
object. I've never seen this used and was wondering about the logic
behind it. I had previously assumed that the in keyword passed the
properties of an object to a variable, as you do in a for/in loop. How
is it that it can be used in a comparsion?
example:
var elements = {'html':true}
var myElement = "html";
if(myElement in elements)
alert("True");
I was messing around with someone elses script when I noticed that he
had used the in keyword in an if conditional to compare a string with a
object. I've never seen this used and was wondering about the logic
behind it. I had previously assumed that the in keyword passed the
properties of an object to a variable, as you do in a for/in loop. How
is it that it can be used in a comparsion?
example:
var elements = {'html':true}
var myElement = "html";
if(myElement in elements)
alert("True");