JavaScript Reflect.set() Method

Last Updated : 17 Jun 2026

The JavaScript Reflect.set() method is used to assign a value to a property of an object. It returns a Boolean value indicating whether the property was successfully updated.

In this chapter, you will learn how to use the Reflect.set() method to add and modify properties of objects and arrays.

What is JavaScript Reflect.set() Method?

The JavaScript Reflect.set() method assigns a value to a specified property of an object. It works similarly to the assignment operator (=) but returns a Boolean value indicating whether the operation was successful.

Syntax of JavaScript Reflect.set() Method

Use the following syntax to set the value of a property:

Parameters

  • obj - The target object on which the property is to be set.
  • key - The name of the property to set.
  • value - The value to assign to the property.
  • receiver (optional) - The value of this provided for the call to the target if a setter is encountered.

Return Type/Value

The Reflect.set() method returns a Boolean value.

  • Returns true if the property is successfully set.
  • Returns false if the property cannot be set.

Exceptions

  • Throws a TypeError if the target is not an object.

Examples of JavaScript Reflect.set() Method

The following examples demonstrate how to use the Reflect.set() method.

Example 1: Set a Value in an Array

In this example, we use the Reflect.set() method to assign a value to a specific index of an array.

Output:

"gosse"

Example 2: Add a Property to an Object

In this example, we use the Reflect.set() method to add a new property and assign a value to an object.

Output:

32

Example 3: Set Properties on Multiple Objects

In this example, we use the Reflect.set() method to add properties to multiple objects and access their values.

Output:

7
4

Browser Support

BrowserVersion
Chrome49
Edge12
Firefox42
Opera36