Reflect.has() JavaScript

The JavaScript Reflect.has() method determines if a property exists in an object. It is similar to in operator as a function.

Syntax:

Reflect.has(target, propertyKey)

Parameters: target: It represents the object on which the property existing checks have to be performed. propertyKey: It represents the name of the property to check.

Return: It returns true if the specified property exists in the object otherwise, it returns false.

Note: It throws TypeError, if the target is not an Object.

Example 1:

<!DOCTYPE html>
<html>
<body>
<script>
const obj = {prop:100};
document.write(Reflect.has(obj, 'prop'));
</script>
</body>
</html>

Example 2:

<!DOCTYPE html>
<html>
<body>
<script>
const object1 = {
property1: "w3spoint"
};
document.write(Reflect.has(object1, 'property1'));
document.write("</br>");
document.write(Reflect.has(object1, 'property2'));
document.write("</br>");
document.write(Reflect.has(object1, 'toString'));
</script>
</body>
</html>
Please follow and like us:
Content Protection by DMCA.com