# Object.{pick,omit}

**URL:** <https://es.discourse.group/t/object-pick-omit/515>\
**Category:** 💡 Ideas\
**Created:** [October 26, 2020, 8:42am UTC](https://es.discourse.group/t/object-pick-omit/515 "2020-10-26T08:42:46Z")\
**Posts on this page:** 1\
**Showing post:** 59

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [June 12, 2021, 2:54am UTC](https://es.discourse.group/t/object-pick-omit/515/59 "2021-06-12T02:54:49Z")

</div>

Just to clarify, are you two (@lightmare and @aleen42) proposing these bracket syntaxes in addition to the `full.{a, b}` syntax that @jamiebuilds proposed? Or in place of? I presume it's in place of?

I'm going to make a couple of arguments in favor of @jamiebuilds's syntax:

It's built for the most common use case of just picking pre-known properties off of an object. You don't have to use strings (but we can still add support for dynamic key if wanted. Similar to how object literals and destructuring are built for the most common use case of non-dynamic keys, but have support for dynamic keys)

It could be extended to support other nice features, such as renaming while picking the properties off, or setting default values if the properties don't exist. Hopefully, you can see a parallel with object destructuring. With object destructuring, we pick properties off and put them in the local namespace. With this pick syntax, we pick properties off and put them in a new object.

It's actually got a minor prior art in Microsoft's Bosque language as well (see [here](https://github.com/microsoft/BosqueLanguage/blob/c841324bf706b60d8a9dbb1519a8e5227fc5bd9f/docs/language/overview.md#06-bulk-algebraic-data-operations)), which has an object pick syntax that's exactly the same.

(I've actually started a thread in the past which suggested having this kind of syntax [here](https://es.discourse.group/t/object-restructuring-syntax/651), which is why I like it so much)

```javascript
// pick a, b, and c off
// if b doesn't exist, set it to 2
// rename c to C
const newObj = oldObj.{ a, b = 2, c: C }

// Example of dynamic keys
// (again, do you see the parallel with object destructuring?)
const anotherNewObj = something.{ x, [key1], [key2]: renamedKey }

```

---

_[View the full topic](https://es.discourse.group/t/object-pick-omit/515)._
