Standard built-ins
Object.defineProperty()
Defines or redefines an own property using descriptor attributes. Omitted flags on a new data property default false; incompatible changes throw TypeError.
Formal Syntax & Structure
javascript syntaxjavascript
Object.defineProperty(obj, key, descriptor)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| obj | Object | Target object. |
| key | String | Symbol | Property key. |
| descriptor | Object | Property descriptor with valid data or accessor fields. |
Return Value
Object
Same target.
Working Example
Example Snippetjavascript
const o={};Object.defineProperty(o,"n",{value:2});console.log(o.n,Object.keys(o).length);