p5.js | arrayCopy() function
The arrayCopy() function in p5.js is used to copy a part of source array elements to another destination array. This function is depreciated from future versions.
Syntax:
arrayCopy( src, src_pos, dst, dst_pos, length )
Parameters: This function accepts five parameters as mentioned above and described below:
- src: This is the source array whose elements to be copied into another array.
- src_pos: This is the position of source array elements from where the element is copied.
- dst: This is the destination array where copied source array element is to be pasted.
- dst_pos: This is the position of destination array where source array element is to be pasted.
- length: This is the number of elements to be copied from source array.
Return Value: It returns a new copied destination array.
Below programs illustrate the arrayCopy() function in p5.js:
Example 1: This examples uses arrayCopy() function to copy source array elements to destination array.
function setup() { // Creating Canvas of given size createCanvas(500, 90); } function draw() { // Set the background color background(220); // Initializing the source array let src = ['IT', 'CSE', 'ECE']; // Initializing the source array position // from where the elements are to be copied. let src_pos = 1; // Initializing the destination array let dst = ['Ram', 'Shyam', 'Geeta']; // Initializing the destination position // where copied elements are to be pasted. let dst_pos = 0; // Initializing the number of source array elements // which are to be copied. let length = 2; // Calling to arrayCopy() function. arrayCopy(src, src_pos, dst, dst_pos, length); // Set the size of text textSize(16); // Set the text color fill(color('red')); // Getting new destination array text("New destination array is : " + dst, 50, 30); } |
Output:

Example 2: This examples uses arrayCopy() function to copy source array elements to destination array.
function setup() { // Creating Canvas of given size createCanvas(500, 90); } function draw() { // Set the background color background(220); // Initializing the source array let src = ['geeks', 'Students', 'Teachers']; // Initializing the source array position // from where the elements are to be copied. let src_pos = 2; // Initializing the destination array let dst = ['A', 'B', 'C']; // Initializing the destination position // where copied elements are to be pasted. let dst_pos = 1; // Initializing the number of source array elements // which are to be copied. let length = 1; // Calling to arrayCopy() function arrayCopy(src, src_pos, dst, dst_pos, length); // Set the size of text textSize(16); // Set the text color fill(color('red')); // Getting new destnation array text("New destination array is : " + dst, 50, 30); } |
Output:

Reference: https://p5js.org/reference/#/p5/arrayCopy
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- PHP | max( ) Function
- p5.js | box() Function
- D3.js | d3.map.set() Function
- PHP | end() Function
- CSS | rgb() Function
- PHP | Ds\Map get() Function
- PHP | min( ) Function
- D3.js | d3.rgb() Function
- p5.js | value() Function
- D3.js | d3.lab() Function
- PHP | dir() Function
- p5.js | int() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



