Static p5_sys::global::arrayCopy[][src]

pub static arrayCopy: ArrayCopyInternalType
Expand description

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

let src = ['A', 'B', 'C'];
let dst = [1, 2, 3];
let srcPosition = 1;
let dstPosition = 0;
let length = 2;

print(src); // ['A', 'B', 'C']
print(dst); // [ 1 ,  2 ,  3 ]

arrayCopy(src, srcPosition, dst, dstPosition, length);
print(dst); // ['B', 'C', 3]

Overloads

src the source Array

srcPosition starting position in the source Array

dst the destination Array

dstPosition starting position in the destination Array

length number of Array elements to be copied


src the source Array

dst the destination Array

length? number of Array elements to be copied