> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.itential.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.itential.com/_mcp/server.

# copyWithin

> Use the copyWithin task to copy a portion of an array to a new location within the same array without modifying its size.

The `copyWithin` task copies a portion of an array within the same array. A specified part of an array is copied to a new location in the same array without modifying its size (length).

## Potential use case

This task overwrites the original array by copying array elements to another position in the same array. Suppose you have a list of emails and you want to search for any duplicates in the list. You can specify where to start searching in the list (for example, `0` for the beginning) and where to end the search. You can also specify where in the email list the results will be copied to.

## Properties

| Incoming | Type   | Description                                                                                             |
| -------- | ------ | ------------------------------------------------------------------------------------------------------- |
| `arr`    | Array  | Required. The array to copy.                                                                            |
| `target` | Number | Required. The index position (destination) to copy the sequence to. The `target` is a zero-based index. |
| `start`  | Number | The index position to start copying elements from.                                                      |
| `end`    | Number | The index position where to stop copying elements.                                                      |

| Outgoing      | Type  | Description         |
| ------------- | ----- | ------------------- |
| `copiedArray` | Array | The modified array. |

## Example

In this example:

* The `arr` value is `["a","b","c","d"]`. It has four elements.
* The `target` index is `2`. This means the destination begins at the `2` location in the index. Indexing starts at `0` and counts up from there.
* The `start` variable of the search is `0`, which is the first location in the array being searched.
* The `end` variable is `2`, indicating the search stops after the first two characters in the index and does not copy anything after that.

![](/_fern-img/8393b0f6d79fcd165b4903afd9670e6189b9cdef73b7cdf866558814cf6359f3.webp)

The result of this task copies the first two characters (`"a"` at index 0, `"b"` at index 1) and places that copy at index positions 2 and 3. The `copiedArray` that returns will be `["a","b","a","b"]`.

![](/_fern-img/71f8b8b78ba0be802db8f74fe933e54506f0347cebcaa8a4125398d252cb6d5e.webp)