What does the following syntax mean:
1 in [1,2,3,5]
I know it doesn’t search for 1 in the array. But what does it do?
I’ve seen it used in loops:
for (var i in testArray)
{
}
But have also seen this used by itself. Does it mean check if the literal is a valid index in the array or object that is the other operand?
literal
inobject means: “Get a property literal from object.”When used in a loop, the engine will try to access all properties of the object.
1 in [1,2,3,4]doesn’t check for an occurence of an element with a value of1, but it checks whether element 1 (array[1]) exists or not.