JavaScript in Operator

The in operator is an inbuilt operator in JavaScript which is used to check whether a particular property exists in an object or not. It returns a boolean value true if the specified property is in an object, otherwise, it returns false.
Syntax:
prop in object
Parameters: This function accepts the following parameter as mentioned above and described below:
- prop: This parameter holds the string or symbol that represents a property name or array index.
- object: This parameter is an Object which is to be checked whether it contains the prop.
Return value: This method returns a boolean value:
- true: The value true is returned if the specified property is found in an object.
- false: The value false is returned if the specified property is not found in an object.
Example 1: Below is an example of the in-operator.
Javascript
| <script>     functiongfg() {     // Illustration of in operator     const array = ['zambiatek', 'for',                 'zambiatek']          // Output of the indexed number     console.log(0 inarray);          // Output of the Value     console.log('for'inarray);          // output of the Array property     console.log('length'inarray);     }     gfg(); </script> | 
Output:
true false true
Example 2: This example shows the use of the in operator in Javascript.
Javascript
| <script>     // Illustration of in operator     const array = ['zambiatek', 'zambiatekfor',                 'zambiatek', 'zambiatek1']          // Output of the indexed number     console.log(0 inarray)             console.log(2 inarray)         console.log(5 inarray)              // Output of the Value     console.log('for'inarray)     console.log('zambiatek'inarray)          // output of the Array property     console.log('length'inarray) </script> | 
Output:
true true false false false true
Example 3: This example shows the use of the in operator in Javascript.
Javascript
| <script>     // Illustration of in operator     const object = { val1: 'Geeksforzambiatek',                     val2: 'Javascript',                     val3: 'operator',                     val4: 'in'};          console.log('val1'inobject);          deleteobject.val1;     console.log('val1'inobject);          if('val1'inobject === false) {     object.val1 = 'GEEKSFORGEEKS';     }          console.log(object.val1); </script> | 
Output:
true false "GEEKSFORGEEKS"
We have a complete list of Javascript Operators, to check those please go through the Javascript Operators Complete Reference article.
Supported Browsers: The browsers supported by JavaScript in operator are listed below:
- Google Chrome
- Firefox
- Opera
- Safari
- Edge
- Internet Explorer
 
				 
					


