Open In App

p5.js concat() function

The concat() function in p5.js is used to concatenate the two given arrays. This function is depreciated from future versions and uses First_array.concat(Second_array) instead. 

Syntax:



concat(First_array, Second_array)

Parameters: This function accepts two parameters as mentioned above and described below:

Return Value: It returns a new concatenated array. Below program illustrates the concat() function in p5.js: 



Example: This example uses concat() function to concatenate two arrays. 




function setup() {
  
    // Creating Canvas size
    createCanvas(500, 90);
}
  
function draw() {
  
    // Set the background color 
    background(220);
  
    // Initializing the arrays
    let Array1 = ['IT', 'CSE', 'ECE'];
    let Array2 = ['Civil', 'Mechanical'];
  
    // Calling to concat() function.
    let Array3 = concat(Array1, Array2);
  
    // Set the size of text 
    textSize(16);
  
    // Set the text color 
    fill(color('red'));
  
    // Getting new concatenated array
    text(& quot;New concatenated array is: & quot;
    + Array3, 50, 30);
}

Output: 

Reference: https://p5js.org/reference/#/p5/concat

Article Tags :