The copyWithin task is used to copy 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 (i.e., length).
Potential Use Case
This task method 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 to see if there are any copies in the list. You can specify where to start searching in the list (e.g., "0" being the beginning) and then where to end the search. You can also specify where in the email list the results will copy to.
Input and output parameters are shown below.
||Array||Required. The array to copy.|
||Number||Required. The index position (destination) to copy the sequence to. The
||Number||The index position to start copying elements from.|
||Number||The index position where to stop copying elements.|
||Array||The modified array.|
In this IAP example:
["a","b","c","d"]. It has four elements.
2. This means the search begins at the "2" location in the index. Remember that indexing starts at "0" and counts up from there.
startvariable of the search is
0, which is the first location in the array being searched.
2, indicating the search stops after the first 2 characters in the index and does not copy anything after that.
The result of this task will make a copy of the first 2 characters |"a"= 0|"b"= 1| and then place that copy in the second character position of the index with |"a"= 2|"b"= 3|. The
copiedArraythat returns will be