← TechnologyThe essentials of

copyWithin(): moving values inside the array

Publisher: ResumeMaker • 1 source

Published: 22 Oct 2026 13:13 · Updated: 22 Oct 2026 13:13

AI source check: 21 Oct 2026 12:40. This is not editorial approval.

In a few sentences

In brief

The method copies in place and does not increase the length.

Useful to know

copyWithin() copies part of an array onto another part of it. For example, [1, 2, 3, 4].copyWithin(0, 2) gives [3, 4, 3, 4]. The length remains four . [1]

This is different from adding more elements. Existing target positions are overwritten. Before use, write down which indexes are the source and which are the target, especially when overlapping. If you need independent retrieval without change, use a copy method. The name suggests the scope: the operation remains inside the same container.

Sources

For further detail and to check the information:

  1. [1] MDN — Array.copyWithin ↗