# Provide an easy way to create a new array, filled via a mapping function

**URL:** <https://es.discourse.group/t/provide-an-easy-way-to-create-a-new-array-filled-via-a-mapping-function/1056>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [October 25, 2021, 11:54am UTC](https://es.discourse.group/t/provide-an-easy-way-to-create-a-new-array-filled-via-a-mapping-function/1056 "2021-10-25T11:54:38Z")\
**Posts on this page:** 1\
**Showing post:** 57

<div class="post-metadata">

**Author:** ![Rudxain](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/rudxain/32/2272_2.png) [@Rudxain](https://es.discourse.group/u/Rudxain)\
**Post date:** [October 27, 2022, 8:39am UTC](https://es.discourse.group/t/provide-an-easy-way-to-create-a-new-array-filled-via-a-mapping-function/1056/57 "2022-10-27T08:39:24Z")

</div>

I "gathered some data" (actually, it was just personal experience) related to this. Look at [this commit history](https://github.com/bjpop/js-turtle/commits/cddcf39206735bb0f974a5fc9a093388467ff2d1/examples/bounce.js).

As you can see, we started with `Array(n)`+`for` loop (probably because in "the old days" pre-allocating an array was faster than repeatedly `push`ing values, otherwise the garbage-collector and the allocator would work too much).

Then we transitioned to `[]`+`while (n--)`+`push`. Then `Array(n).fill().map()`. And finally `Array.from({ length }, ...)`.

I was confused as to why this is a "hacky solution", because I thought `{ length }` was a named-arg bag. Then I read the docs, and realized the arg is supposed to be iterable or "array-like", and `{ length }` **is neither but it still works** , because it has the minimal requirement to be considered "array-like" (the `length` prop). The mapping fn is also discarding **both** args (value and index), which makes it a "filler" rather than a "mapper"

---

_[View the full topic](https://es.discourse.group/t/provide-an-easy-way-to-create-a-new-array-filled-via-a-mapping-function/1056)._
