# Object.isEmpty

**URL:** <https://es.discourse.group/t/object-isempty/166>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [December 18, 2019, 4:55pm UTC](https://es.discourse.group/t/object-isempty/166 "2019-12-18T16:55:55Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [December 19, 2019, 11:26pm UTC](https://es.discourse.group/t/object-isempty/166/9 "2019-12-19T23:26:56Z")

</div>

> [@claudepache](#):
>
> I have a method in my personal library that is roughly equivalent to:
> 
> ```javascript
> Object.hasNoKey = function (o) {
> return Object.keys(o).length === 0
> }
> 
> ```

I'd prefer this kind of semantics for an `Object.isEmpty` - it's simple and everyone interprets it as that low-level primitive. It also fits in with the rest:

- `Object.keys(new Map([["a", 1], ["b", 2]]))` returns `[]`, not `["a", "b"]`.
- `Object.values(new Map([["a", 1], ["b", 2]]))` returns `[]`, not `[1, 2]`.
- `Object.entries(new Map([["a", 1], ["b", 2]]))` returns `[]`, not `[["a", 1], ["b", 2]]`.

Better might be just `Object.size(o)`, which returns effectively `Object.keys(o).length`. I've personally have had a couple cases where the length was useful independent of it, and it's easy enough to check `Object.size(o) === 0` or `!Object.size(o)` for `Object.isEmpty(o)`. And in nearly all runtimes, this is a _very_ cheap O(1) access for non-proxies, cheaper than even property access.

---

_[View the full topic](https://es.discourse.group/t/object-isempty/166)._
