Favorites

JavaScript in Operator

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
in
JavaScript Relational OperatorThis operator is supported by all modern browsers.
Updated 28th November 2026

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 object

Example

const car = { make: 'Mazda', year: undefined };
console.log('make' in car, 'year' in car, 'color' in car);
console.log('toString' in car);
console.log(0 in ['a'], 'a' in ['a']);
console.log('fetch' in window);

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.

This operator is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee