TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript Reflect has() Method

JavaScript Reflect has() Method with examples on javascript reflect methods, apply() construct(), defineProperty() method, deleteProperty(), get(), getOwnPropertyDescriptor(), getPrototypeOf(), has(), isExtensible(), ownKeys(), setPrototypeOf() etc.

<< Back to JAVASCRIPT

JavaScript Reflect.has() Method

The 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:

Chrome 49
Edge 12
Firefox 42
Opera 36

Example 1

const object1 = {
  property1: 42
};
console.log(Reflect.has(object1, 'property1'));

Output:

 true

Example 2

const object1 = {
  property1: 42
};
console.log(Reflect.has(object1, 'property2'));

Output:

 false

Example 3

var 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




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf