C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Reflect.has() MethodThe static Reflect.has() method is used to check if a property exists in an object. It works like the in operator as a function. Syntax:Reflect.has(target, propertyKey) Parameters:target: It is the object in which to look for the property. propertyKey: It is the name of the property to check. Return value:It returns a Boolean which indicates whether or not the target has the property. Exceptions:A TypeError, if the target is not an Object. Browser Support:
Example 1const object1 = { property1: 42 }; console.log(Reflect.has(object1, 'property1')); Output: true Example 2const object1 = { property1: 42 }; console.log(Reflect.has(object1, 'property2')); Output: false Example 3var x = { foo: 1 }; console.log(Reflect.has(x, 'foo')); console.log('foo' in x); console.log(Reflect.has(x, 'bar')); console.log('bar' in x); Output: true true false false
Next TopicJavaScript Reflect
|