C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Object.defineProperties() MethodThe Object.defineProperties() method defines new or modifies existing properties directly on an object, and returning the object. Syntax:Object.defineProperties(obj, props) ParameterObj: The object on which to define or modify properties. Props: An object whose own enumerable properties constitute descriptors for the properties to be defined or modified. Return:This method reruns an object that was passed to the function. Browser Support:
Example 1const object1 = {}; Object.defineProperties(object1, { property1:{ value: 44, } }); console.log(object1.property1); Output: 44 Example 2const object1 = {}; Object.defineProperties(object1, { property1: { value: 142, value: 422, value: 423, }, property2: {} }); console.log(object1.property1); Output: 423 Example 3const obj = {}; Object.defineProperties(obj, { property1: { value: 142, value: 422, value: 423, }, property2: { value: 22, value: 12,} }); console.log(obj.property1,obj.property2); Output: 423 12
Next TopicJavaScript Objects
|