objectHasOwnProperty

The objectHasOwnProperty task checks whether the object has a specified property as its own property. This is useful for checking if the object has inherited the property rather than being its own.

The result returns a boolean value (true or false) indicating whether the object has the given property as its own property. If the object has a property with the name contained in the string argument, it returns true. Otherwise it returns false.

Potential use case

This task is a convenient method to check if a specific property exists in an object (or not) since it returns true/false accordingly. Using this task also allows you to test for properties you have manually created on your current object.

Another benefit of objectHasOwnProperty is that it can be initialized with any object by using the string as an argument. It returns true if the value is available to the object, or false if it is not. If you want to check for the existence of properties without necessarily checking their value, this task is well suited for that purpose.

Properties

InputTypeDescription
objObjectRequired. The object to test.
propStringRequired. The string that contains the property to check.
OutputTypeDescription
resultBooleanReturns true if the object owns the specified property; false otherwise.

Example 1

In this example, the incoming reference variable for prop is “name” and the outgoing result returns true, indicating the object contains the specified property.

objectHasOwnProperty task with prop set to name
objectHasOwnProperty task output showing result true

Example 2

In this example, the incoming reference variable for prop is “type” and the result returns false, indicating the object does not contain that given property.

objectHasOwnProperty task with prop set to type
objectHasOwnProperty task output showing result false