# Array.prototype.size

**URL:** <https://es.discourse.group/t/array-prototype-size/481>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [September 21, 2020, 8:48pm UTC](https://es.discourse.group/t/array-prototype-size/481 "2020-09-21T20:48:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathantneal](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jonathantneal/32/441_2.png) [@jonathantneal](https://es.discourse.group/u/jonathantneal)\
**Post date:** [September 21, 2020, 8:48pm UTC](https://es.discourse.group/t/array-prototype-size/481/1 "2020-09-21T20:48:28Z")

</div>

It would be conveniently consistent if collection-like objects could all return their number of items from a `size` property.

```javascript
set = Set([
  'What did Yoda say when he saw himself in 4K?',
  'HDMI.'
])
arr = Array.from(set)
arr.size === set.size // 2 true it is

```

Downsides from my limited perspective:

- Two properties (`length` and `size`) for the same thing.
- Possible conflicts with ancient user land libraries?
- Derails false-etamology-like explanations I’ve invented to justify the difference outside “because time and Java”.

Alternatives from my limited perspective:

- Something like `Symbol.size` that does the same thing, tho it may offer little over a userland helper pattern.

---

<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:** [September 30, 2020, 9:45am UTC](https://es.discourse.group/t/array-prototype-size/481/2 "2020-09-30T09:45:36Z")

</div>

I did some digging into old archives and found some answers:

> - Two properties (`length` and `size`) for the same thing.

`length` was [explicitly reserved for indexed types](https://esdiscuss.org/topic/nov-17-meeting-notes#content-12) and is explicitly used by the array-like protocol (for `Array.from`, all the `Array.prototype` methods, and so on), so they're not _quite_ the same thing.

> - Derails false-etamology-like explanations I’ve invented to justify the difference outside “because time and Java”.

The `size` property name was in fact derived from Java, though they obviously didn't just pull it directly without modification: [Map/Set.prototype.size](https://esdiscuss.org/topic/map-set-prototype-size). Apparently, Firefox shipped a `size` method on their own in Aurora (their old nightly) leading up to that.
