The below examples will help you understand the uses of the operator.
Example 1: Using the in operator with objects. Let’s create an object first, to create an object we have to assign key-value pairs.
We will check whether the key exists in the object or not by using the in operator.
Output: We have checked if the ‘User’ key is in the object or not, if it is in the object then print Found otherwise Not found.
Example 2: Using the in operator with arrays. Let’s create an array first, to create an array we have to assign values to the array in square brackets.
We will check whether the index value exists in the array or not,
Output: We have checked if index 1 is present in the array or not.