Reference arrayCopy()

arrayCopy()

Copies an array (or part of an array) to another array. The src array is copied to the dst array, beginning at the position specified by srcPosition and into the position specified by dstPosition. The number of elements to copy is determined by length. Note that copying values overwrites existing values in the destination array. To append values instead of overwriting them, use concat().

The simplified version with only two arguments, arrayCopy(src, dst), copies an entire array to another of the same size. It is equivalent to arrayCopy(src, 0, dst, 0, src.length).

Using this function is far more efficient for copying array data than iterating through a for() loop and copying each element individually.

Examples

Syntax

arrayCopy(src, srcPosition, dst, dstPosition, length)
arrayCopy(src, dst, [length])

Parameters

src
Array:

the source Array

srcPosition
Integer:

starting position in the source Array

dst
Array:

the destination Array

dstPosition
Integer:

starting position in the destination Array

length
Integer:

number of Array elements to be copied

Notice any errors or typos? Please let us know. Please feel free to edit src/utilities/array_functions.js and open a pull request!

Related References