Our volunteers haven't translated this article into हिन्दी (भारत) yet. Join us and help get the job done!
You can also read the article in English (US).

The in operator returns true if the specified property is in the specified object or its prototype chain.


prop in object


A string or symbol representing a property name or array index (non-symbols will be coerced to strings).
Object to check if it (or its prototype chain) contains the property with specified name.


The following examples show some uses of the in operator.

// Arrays
var trees = ['redwood', 'bay', 'cedar', 'oak', 'maple'];
0 in trees        // returns true
3 in trees        // returns true
6 in trees        // returns false
'bay' in trees    // returns false (you must specify the index number, not the value at that index)
'length' in trees // returns true (length is an Array property)
Symbol.iterator in trees // returns true (arrays are iterable, works only in ES2015+)

// Predefined objects
'PI' in Math          // returns true

// Custom objects
var mycar = {make: 'Honda', model: 'Accord', year: 1998};
'make' in mycar  // returns true
'model' in mycar // returns true

You must specify an object on the right side of the in operator. For example, you can specify a string created with the String constructor, but you cannot specify a string literal.

var color1 = new String('green');
'length' in color1 // returns true

var color2 = 'coral';
// generates an error (color2 is not a String object)
'length' in color2

Using in with deleted or undefined properties

If you delete a property with the delete operator, the in operator returns false for that property.

var mycar = {make: 'Honda', model: 'Accord', year: 1998};
delete mycar.make;
'make' in mycar;  // returns false

var trees = new Array('redwood', 'bay', 'cedar', 'oak', 'maple');
delete trees[3];
3 in trees; // returns false

If you set a property to undefined but do not delete it, the in operator returns true for that property.

var mycar = {make: 'Honda', model: 'Accord', year: 1998};
mycar.make = undefined;
'make' in mycar;  // returns true
var trees = new Array('redwood', 'bay', 'cedar', 'oak', 'maple');
trees[3] = undefined;
3 in trees; // returns true

Inherited properties

The in operator returns true for properties in the prototype chain.

'toString' in {}; // returns true


Specification Status Comment
ECMAScript Latest Draft (ECMA-262)
The definition of 'Relational Operators' in that specification.
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Relational Operators' in that specification.
ECMAScript 5.1 (ECMA-262)
The definition of 'The in Operator' in that specification.
ECMAScript 3rd Edition (ECMA-262)
The definition of 'The in Operator' in that specification.
Standard Initial definition. Implemented in JavaScript 1.4.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
Basic supportChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes


Full support  
Full support

See also

दस्तावेज़ टैग और योगदानकर्ता

इस पृष्ठ के लिए योगदानकर्ता: zhuangyin, wbamberg, fscholz, vitaliylag, vTripes, jameshkramer, nmve, kdex, kamoroso94, lewisje, Sebastianz, Havvy, mrienstra, onlyofrajat, Sheppy, Brettz9, ethertank, moreati, mattcg, Sevenspade, Mgjbot, Nickolay, Dria
अंतिम अद्यतन: zhuangyin,