Relational Operators
The in Operator
The in operator returns true if a property is in an object, otherwise false:
Object Example
const person = {firstName:"John", lastName:"Doe", age:50};
("firstName" in person);
("age" in person);
Try it Yourself »
Note
You cannot use in to check for array content like ("Volvo" in cars).
Array properties can only be index (0,1,2,3...) and length.
See the examples below.
Examples
const cars = ["Saab", "Volvo", "BMW"];
("Saab" in cars);
Try it Yourself »
const cars = ["Saab", "Volvo", "BMW"];
(0 in cars);
(1 in cars);
(4 in cars);
("length" in cars);
Try it Yourself »
Browser Support
in
is an ECMAScript3 (JavaScript 1999) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |