VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-in-operator/

⇱ JavaScript in Operator - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript in Operator

Last Updated : 24 Dec, 2025

JavaScript in operator is an inbuilt operator 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.


Output
true
false
true
  • 0 in array returns true because index 0 exists in the array.
  • 'for' in array returns false because the in operator checks for indexes or property names, not values.
  • 'length' in array returns true because length is a built-in property of arrays.

Syntax:

prop in object

Here are some examples of using the in operator:

Example: Using the in Operator to Check Indexes and Properties in an Array.


Output
true
true
false
false
false
true
  • 0 and 2 exist as indexes: true, 5 does not : false.
  • 'for' and 'geeksforgeeks' are values, not property names : false.
  • 'length' is a built-in array property : true.

Example: Using the in Operator to Check the Existence of Properties in an Object.


Output
true
false
GEEKSFORGEEKS
  • 'val1' in object returns true because the property exists
  • After deleting object.val1, it returns false since the property no longer exists.
  • The code checks for the missing property and recreates it with a new value.

Parameters:

  • prop: This parameter holds the string or symbol that represents a property name or array index.
  • object: This parameter is an Object that is to be checked whether it contains the prop.

Return value:

This method returns a boolean value. The value true is returned if the specified property is found in an object, else it returns false.

Also Read:

Comment