Export (0) Print
Expand All

in Operator (JavaScript)

Tests for the existence of a property in an object.

result = property in object


Required. Any variable.


Required. An expression that evaluates to a string expression.


Required. Any object.

The in operator checks if an object has a property named property. It also checks the object's prototype to see if the property is part of the prototype chain.

The following example illustrates the use of the in operator:

// Create an object that has some properties.
var myObject = new Object();
myObject.name = "James";
myObject.age = "22";
myObject.phone = "555 0234";

if ("phone" in myObject)
   document.write ("property is present");
   document.write ("property is not present");

// Output: property is present

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards. See Version Information.

Community Additions

© 2015 Microsoft