TheDeveloperBlog.com

Home | Contact Us

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

JavaScript Reflect get() Method

JavaScript Reflect get() 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.get() Method

The static Reflect.get() method is used to retrieve the property from an object as a function. The first argument is the object and the second argument is the property name.

Syntax:

Reflect.get(target, propertyKey[, receiver])

Parameters:

target: It is the target object on which to get the property.

propertyKey: It is the name of the key to get.

receiver: It is the value of this provided for the call to object if a getter is encountered.

Return value:

It returns the value of 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 u = {p:3};
console.log( Reflect.get ( u , "p" ) === 3 );
// if property key is not found, return undefined just like obj.key
console.log( Reflect.get ( u , "h" ) === undefined ); 
console.log( Reflect.get ( u , "h" ) === 3 );

Output:

true

true

false

Example 2

const x = {p:3};
const y = Object.create (x);
// x is parent of y
console.log (
    Reflect.get ( y, "p" ) === 3
  // Reflect.get will traverse the prototype chain to find property
); 

Output:

true

Example 3

const object1 = {
  x: 1,
  y: 2
};
console.log(Reflect.get(object1, 'y'));
// expected output: 1
var array1 = ['zero', 'one','Carry','marry','charry'];
console.log(Reflect.get(array1, 4));

Output:

 2
 "charry"
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