Get to know MDN better
The JavaScript exception "right-hand side of 'in' should be an object" occurs when the in operator was used to search in strings, or in numbers, or other primitive types. It can only be used to check if a property is in an object.
The in operator can only be used to check if a property is in an object. You can't search in strings, or in numbers, or other primitive types.
Unlike in other programming languages (e.g., Python), you can't search in strings using the in operator.
Instead you will need to use String.prototype.includes(), for example.
Make sure the object you are inspecting isn't actually null or undefined.
The in operator always expects an object.
Be careful when using the in operator to search in Array objects. The in operator checks the index number, not the value at that index.
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.