JavaScript in Operator

You are Here:

JavaScript in Operator

The in operator returns a Boolean value indicates whether the specified property is in the specified object or its prototype chain.

Note: If you set a property to undefined but do not delete it, the in operator returns true for that property.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p id="point"></p> <script> var x = document.getElementById("point"); var bike = {brand: "Honda", color: "red"}; if ("model" in bike === false) bike.model = "cb1000r"; x.innerHTML = "Model : "+bike.model; </script> </body> </html>

Syntax

property in object

Parameter Values

ValueTypeExplanation
propertyRequiredA string representing a property name or array index.
objectRequiredAn object to check if it contains the property with specified name.

Return Values

ValueExplanation
trueIf the specified property is in the specified object.
falseIf the specified property is not in the specified object.

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author