Suggest an editImprove this articleRefine the answer for “Deleting a property from an object”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)A property can be removed with the **`delete`** operator, via destructuring (`{ key, ...rest }`) for an immutable approach, via `Reflect.deleteProperty()`, or by setting its value to `null`/`undefined` without removing the key itself. **Key point:** `delete` mutates the original object and only works on object properties, not variables, while destructuring creates a new object without changing the original.Shown above the full answer for quick recall.Answer (EN)Image## 1. **The** `delete` **operator** The simplest and most common way: ```javascript const user = { name: 'Tim', age: 25, city: 'Kyiv' }; delete user.age; console.log(user); // { name: 'Tim', city: 'Kyiv' } ``` The `delete` operator removes a property **directly from the object**. --- ### Important: - `delete` only works **with object properties**, not with variables. - It returns `true` even if the property did not exist: ```javascript delete user.nonexistent; // true ``` - It **does not affect the prototype**, only the object itself. --- ## 2. **Via destructuring** (an immutable approach) If you want to **create a new object without a property**, without changing the original: ```javascript const user = { name: 'Tim', age: 25, city: 'Kyiv' }; const { age, ...updatedUser } = user; console.log(updatedUser); // { name: 'Tim', city: 'Kyiv' } ``` Here `...rest` collects all the remaining properties, so the removal happens "softly", without changing the original. --- ## 3. **Using** `Reflect.deleteProperty()` This is a modern alternative to `delete`, equivalent in meaning, but used in more formal scenarios (for example, in metaprogramming). ```javascript const user = { name: 'Tim', age: 25 }; Reflect.deleteProperty(user, 'age'); console.log(user); // { name: 'Tim' } ``` The behavior is the same as `delete`, but it returns `true`/`false` more strictly. --- ## 4. **Nulling out or reassigning (when you do not need to physically remove it)** Sometimes it is safer not to delete, but just to clear the value: ```javascript user.age = null; // value logically removed // or user.age = undefined; ``` Such a property stays in the object, but its value is considered "empty". --- ## Summary | Way | Changes the original object | What it does | Note | |---|---|---|---| | `delete obj.key` | Yes | Removes the property | Simple and common way | | `Reflect.deleteProperty(obj, key)` | Yes | The same, but "officially" | Used in metaprogramming | | Destructuring `{ key, ...rest }` | No | Creates a new object without the property | Immutable approach | | `obj.key = null` | Yes | "Clears" the value but does not remove the key | Handy when resetting state |For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.