A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-in-operator/ below:

JavaScript in Operator - GeeksforGeeks

JavaScript in Operator

Last Updated : 12 Jul, 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.

Syntax:
prop in object
Parameters: 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.

Example 1: Below is an example of the in-operator.

JavaScript
function gfg() {
    // Illustration of in operator 
    const array = ['geeks', 'for',
        'geeks']

    // Output of the indexed number 
    console.log(0 in array);

    // Output of the Value 
    console.log('for' in array);

    // output of the Array property 
    console.log('length' in array);
}
gfg();

Example 2: This example shows the use of the in operator in Javascript.

JavaScript
// Illustration of in operator
const array = ['geeksforgeeks', 'geeksfor',
    'geeks', 'geeks1']

// Output of the indexed number
console.log(0 in array)
console.log(2 in array)
console.log(5 in array)

// Output of the Value
console.log('for' in array)
console.log('geeksforgeeks' in array)

// output of the Array property
console.log('length' in array)

Output
true
true
false
false
false
true

Example 3: This example shows the use of the in operator in Javascript.

JavaScript
// Illustration of in operator
const object = {
    val1: 'Geeksforgeeks',
    val2: 'Javascript',
    val3: 'operator',
    val4: 'in'
};

console.log('val1' in object);

delete object.val1;
console.log('val1' in object);

if ('val1' in object === false) {
    object.val1 = 'GEEKSFORGEEKS';
}

console.log(object.val1);

Output
true
false
GEEKSFORGEEKS
Supported Browsers:

We have a complete list of Javascript Operators, to check those please go through the Javascript Operators Complete Reference article.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4