JavaScript in Operator
The in-operator in JavaScript checks if a specified property exists in an object or if an element exists in an array. It returns a Boolean value.
Syntax:
prop in object
Example 1: Here is the basic example of using in operator.
Javascript
let languages = [ "HTML" , "CSS" , "JavaScript" ]; // true (index 1 exists in the array) console.log(1 in languages); // false (index 3 doesn't exist in the array) console.log(3 in languages); |
Output
true false
Example 2: In this example, we are using in operator to check if the “name” property exists (true) and if the “address” property doesn’t exist (false).
Javascript
const Data = { name: "Rahul" , age: 21, city: "Noida" }; // true ("name" property exists in the object) console.log( "name" in Data); // false ("gender" property doesn't exist in the object) console.log( "address" in Data); |
Output
true false
JavaScript Relational operators
JavaScript Relational Operators are used to compare their operands and determine the relationship between them. They return a Boolean value (true or false) based on the comparison result.
Contact Us