JavaScript in Operator
The in operator checks whether a property exists on an object, including properties it inherits.
Description
The in operator returns true if the named property exists in the object or its prototype chain. It checks for the property's existence, so it returns true even when the value is undefined. For arrays it checks indexes, not values.
To check only the object's own properties, use Object.hasOwn(). 'fetch' in window style checks are a common way to detect browser features. Don't confuse it with the for...in loop.
For arrays, in checks indexes, and for strings it can't be used at all, because the right-hand side must be an object; 'a' in 'abc' throws a TypeError. Use includes() to check whether a value is in an array or string. Inside a class, #field in obj checks whether an object has a particular private field, which is a reliable way to test whether it was created by that class.
Properties
- Operator
in- Category
- Relational
- Precedence
- 9 (1 is lowest, 18 is highest)
- Associativity
- left-to-right
Syntax
prop in objectExample
Browser Support
The following information will show you the current browser support for the in operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





