C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Reflect.set() methodThe static Reflect.set() method is used to set the value of an object's property. It returns true if the property was successfully set. Otherwise, it returns false. Syntax:Reflect.set(obj, Key, value[, receiver]) Parameters:Obj: It is the target object on which to set the property. Key: It is the name of the property to set. value: It is the value to set. Receiver: It is the value of this provided for the call to target if a setter is encountered. Return value:This method returns a Boolean which indicates whether or not setting the property was successful. Exceptions:A TypeError, if the target is not an Object. Browser Support:
Example 1const array1 = []; Reflect.set(array1, 2, 'gosse'); console.log(array1[2]); Output: "gosse" Example 2const obj = {}; Reflect.set(obj, 'pro', 32); console.log(obj.pro); Output: 32 Example 3const n={}; const m={}; Reflect.set(n,'ptou',7); console.log(n.ptou); Reflect.set(m,'too',4); console.log(m.too); Output: 7 4
Next TopicJavaScript Reflect
|