# Optional keys in objects

**URL:** <https://es.discourse.group/t/optional-keys-in-objects/523>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [November 3, 2020, 8:10am UTC](https://es.discourse.group/t/optional-keys-in-objects/523 "2020-11-03T08:10:51Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![rumkin](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/rumkin/32/598_2.png) [@rumkin](https://es.discourse.group/u/rumkin)\
**Post date:** [October 23, 2021, 1:03am UTC](https://es.discourse.group/t/optional-keys-in-objects/523/17 "2021-10-23T01:03:55Z")

</div>

Yep, but there is a corner stones here. Some might want to remove `undefined` and `null`, other `NaN` or `Infinity`. Method to delete properties could solve all of this.

```js
Object.clean({a: undefined, b: null}) // => {}
Object.clean({a: false, b: null}, (v) => v !== false) // => {b: null}

// Method modifies target object
let value = {a: undefined}
'a' in value // => true
Object.clean(value)
'a' in value // => false

```

## Usage

```js
function enrich(input, options) {
  return Object.clean({
     ...input, additionalKey: options,
  })
}

```

And syntax for this should be part of [object restructuring syntax](https://es.discourse.group/t/object-restructuring-syntax/651) proposal, which should be more powerful and cover more object manipulation cases.

---

_[View the full topic](https://es.discourse.group/t/optional-keys-in-objects/523)._
