in
Tests whether a property exists in an object or its prototype chain.
Syntax
property in object
Returns
boolean — `true` if the named property is found on `object` or its prototype
chain.
Throws
TypeError— The right-hand operand is not an object.
Examples
const obj = { a: 1 };
console.log("a" in obj);
console.log("b" in obj);
Output
true
false
const arr = [10, 20];
console.log(0 in arr);
console.log(5 in arr);
Output
true
false
const o = {};
console.log("toString" in o);
Output
true
Notes
- Also returns `true` for inherited properties; use `Object.hasOwn()`
for own-only checks.
- For arrays, `in` tests index existence, not values.
- Private class fields can be tested with `#field in obj` (ES2022).
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.0 |
| safari | 1.0 |
| edge | 12 |
| node | 0.10 |