# Array.prototype.toFilled and ... .toCopiedWithin?

**URL:** <https://es.discourse.group/t/array-prototype-tofilled-and-tocopiedwithin/2461>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [November 7, 2025, 4:35pm UTC](https://es.discourse.group/t/array-prototype-tofilled-and-tocopiedwithin/2461 "2025-11-07T16:35:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaxArt](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/maxart/32/2315_2.png) [@MaxArt](https://es.discourse.group/u/MaxArt)\
**Post date:** [November 7, 2025, 4:35pm UTC](https://es.discourse.group/t/array-prototype-tofilled-and-tocopiedwithin/2461/1 "2025-11-07T16:35:55Z")

</div>

The lack of [non-mutating method alternatives](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#copying_methods_and_mutating_methods) for `Array.prototype.fill` and `.copyWithin` has bugged me for a while. And while I understand that `.fill` is mostly used in expressions like `Array(length).fill(0)` where a non-mutating method would make no difference, it can also have other uses following the array creation (e.g. _partially_ fill an array).

Similar argument for `.copyWithin`, although `.toCopiedWithin` might sound awkward (name suggestions are welcome).

Trivial polyfills:

```javascript
Array.prototype.toFilled = function toFilled(...args) {
  return this.slice().fill(...args);
};
Array.prototype.toCopiedWithin = function toCopiedWithin(...args) {
  return this.slice().copyWithin(...args);
};

```

Just a note: methods like `.toReversed` and the like always return _dense_ arrays, while `.slice` does not. Should `.toCopiedWithin` “densify” the returned array?

Of course, the same methods would be available in `TypedArray`s too.

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [November 7, 2025, 5:10pm UTC](https://es.discourse.group/t/array-prototype-tofilled-and-tocopiedwithin/2461/2 "2025-11-07T17:10:15Z")

</div>

Hi @MaxArt - I was the champion of the [Change-array-by-copy proposal](https://github.com/tc39/proposal-change-array-by-copy) that added `.toSorted()` and `toReversed()`.

The proposal originally added non mutating versions of all mutating methods but we agreed to reduce the scope.

> <https://github.com/tc39/proposal-change-array-by-copy/issues/27#issuecomment-909404729>
>
> \_This issue is a consolidation of #24 by @benlesh (thanks for opening the discus…sion on this!)\_
> 
> \---
> 
> This thread intends to propose the following reduction of scope. This has been discussed in the last Record & Tuple meeting but has not been validated, pending the definition fo the exact scope and further discussion.
> 
> \`\`\`diff
> \- Array.prototype.filled(value, start, end) -\> Array
> \- Array.prototype.copiedWithin(copiedTarget, start, end) -\> Array
> \- Array.prototype.popped() -\> Array
> \- Array.prototype.pushed(values...) -\> Array
> + Array.prototype.reversed() -\> Array
> \- Array.prototype.shifted() -\> Array
> + Array.prototype.sorted(compareFn) -\> Array
> + Array.prototype.spliced(start, deleteCount, ...items) -\> Array
> \- Array.prototype.unshifted(...values) -\> Array
> + Array.prototype.with(index, value) -\> Array
> 
> \# Key:
> \- to be removed
> + will be kept
> \`\`\`
> 
> \_updated to reflect our current intent to change (See https://github.com/tc39/proposal-change-array-by-copy/issues/27#issuecomment-909404729 )\_
> 
> The rationale behind this proposed change is that those functions could be replaced with slice & concatenation techniques that would be as explicit. It would also prevent unwanted over-copying of arrays, notably by preventing chaining of those operations. Finally it reduces web-compatibility risk.
> 
> The main objection would be that those methods have been designed around Tuples in the first place and could be useful there. As we want to keep both proposals in sync we would have to remove them from Tuples as well.

---

<div class="post-metadata">

**Author:** ![MaxArt](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/maxart/32/2315_2.png) [@MaxArt](https://es.discourse.group/u/MaxArt)\
**Post date:** [November 7, 2025, 6:22pm UTC](https://es.discourse.group/t/array-prototype-tofilled-and-tocopiedwithin/2461/3 "2025-11-07T18:22:57Z")

</div>

Very interesting insights, thank you @aclaymore .

Nevertheless, I’ve found working around the lack of `.toFilled` particularly annoying, although it could be just me. Do you think there’s ground the decision could be revisited - about `.fill` at least?

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [November 7, 2025, 9:22pm UTC](https://es.discourse.group/t/array-prototype-tofilled-and-tocopiedwithin/2461/4 "2025-11-07T21:22:48Z")

</div>

> [@MaxArt](#):
>
> Do you think there’s ground the decision could be revisited - about `.fill` at least

The case would need to be made why `.slice().fill(v)` or `.map(() => v)` (if the array is already dense) are not sufficient and a common enough problem to prompt the addition of a new method.

A common starting point is searching open source to find how common a problem may be. For example: [Researching existing code corpora · Issue #37 · tc39/proposal-change-array-by-copy · GitHub](https://github.com/tc39/proposal-change-array-by-copy/issues/37) which, at the time, showed `fill` and `copyWithin` appeared in the fewest repositories.
