Reflect.get(target, propertyKey)reads a property from an object and returns its value. It does the same as target[propertyKey], but as a function call.
An optional third argument, receiver, is the value that this will have if the property is a getter. This is very useful inside a Proxy, where it keeps getters working correctly.
Remember
Reflect.get(target, key, receiver)
target → the object to read from
key → property name (string or symbol)
receiver → optional: this for a getter
missing property → undefined
target must be an object, or TypeError
Syntax
Pass an object and the name of the property to read.
// ECMAScript 2015 (ES6)
Reflect.get(target, propertyKey)
Reflect.get(target, propertyKey, receiver)
// target : an object
// propertyKey : a string or a symbol
// receiver : optional, the this value for a getter
// returns : the value of the property
// throws : TypeError if target is not an object
Parameters
Parameter
Description
target
Required. The object to read from. If it is not an object, a TypeError is thrown.
propertyKey
Required. The name of the property: a string or a symbol. Numbers are turned into strings.
receiver
Optional. The value to use as this when the property is a getter. It defaults to target.
Return Value
Return Value
Description
Any value
The value of the property. Inherited properties from the prototype are found too. If the property does not exist, you get undefined.
TypeError (thrown)
target is not an object, for example a number or a string.
JavaScript Examples
Example 1 — Read Properties
Read an object property, a missing property, an array item, an array length and a symbol key.
Own: Ann
Inherited: Hello
toString is a function: function
String target: TypeError
Dot notation: 3
How It Works
Own and inherited.get() looks at the object first and then up the prototype chain, so greeting and even toString are found.
Primitives are rejected. A string is not an object, so Reflect.get("abc", "length") throws a TypeError.
Dot notation is more relaxed."abc".length works because JavaScript quietly wraps the string in an object first.
Compatibility
Browser & Runtime Support
Reflect.get() is part of ES2015 (ES6), together with the Reflect object. Every current browser and Node.js has it.
✓ ES2015 · Widely supported
Reflect.get()
Supported in Chrome 49+, Edge 12+, Firefox 42+, Safari 10+, Opera 36+ and Node.js 6+. Internet Explorer never got it.
ES2015Standard since
Google Chrome49+ · Desktop & Mobile
Full support
Microsoft Edge12+ · Chromium and legacy
Full support
Mozilla Firefox42+ · Desktop & Mobile
Full support
Apple Safari10+ · macOS & iOS
Full support
Opera36+ · Chromium based
Full support
Samsung InternetRecent versions · Android
Supported
Android WebView49+ · Chromium based
Supported
Node.js6+ · Server runtime
Supported
DenoSupported · JavaScript runtime
Supported
BunSupported · JavaScript runtime
Supported
Internet ExplorerNo native support
Not supported
Reflect.get()Excellent
Bottom line: Safe to use in every current browser and in Node.js. The only thing to plan for is Internet Explorer, which has no Reflect at all.
Frequently Asked Questions
It reads a property from an object and returns its value, like obj[key], but as a function call. It also accepts a receiver, the value to use as this when the property is a getter.
The receiver is the value of this inside a getter. By default it is the target object. In a Proxy get trap you pass the proxy as the receiver, so that getters read other properties through the proxy as well.
The result is the same for objects. Reflect.get() is a function, supports a receiver, accepts symbols and computed keys easily, and throws a TypeError if the target is not an object, while obj.property works on primitives too.
You get undefined, not an error. Use Reflect.has(target, key) if you need to know whether the property exists at all.
Inside a get trap, return Reflect.get(target, key, receiver) to read the property in the normal way. You can add logging or checks before it without breaking getters.