Saturday, October 18, 2025
HomeLanguagesJavascriptp5.js join() function

p5.js join() function

The join() function in p5.js is used to join the input array of strings into a single string using separator. This separator might be any character which gets their position in between two strings of the input array.

Syntax:

join(Array, Separator)

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

  • Array: This is the array of strings which are to be joined.
  • Separator: This is any character to be placed in between two strings of the input array.

Return Value: It returns the joined strings.

Below programs illustrate the join() function in p5.js:

Example 1: This example uses join() function to join the input array elements.




function setup() { 
   
    // Creating Canvas size
    createCanvas(450, 120); 
} 
   
function draw() { 
       
    // Set the background color 
    background(220); 
     
    // Initializing the Array of strings
    let Array1 = ["Geeks", "for", "Geeks"];
    let Array2 = ["1", "2", "3"];
    let Array3 = ["a", "A", "b", "B"];
     
    // Initializing the separator character
    let Separator1 = "/";
    let Separator2 = "&";
    let Separator3 = "*";
           
     
    // Calling to join() function.
    let A = join(Array1, Separator1);
    let B = join(Array2, Separator2);
    let C = join(Array3, Separator3);
           
    // Set the size of text 
    textSize(16); 
       
    // Set the text color 
    fill(color('red')); 
     
    // Getting joined strings
    text("Joined string is: " + A, 50, 30);
    text("Joined string is: " + B, 50, 60);
    text("Joined string is: " + C, 50, 90);
        
} 


Output:

Example 2: This example uses join() function to join the input array elements.




function setup() { 
   
    // Creating Canvas size
    createCanvas(450, 120); 
} 
   
function draw() { 
       
    // Set the background color 
    background(220);
           
    // Calling join() function over the parameter
    // Array of strings and separator
    let A = join(["kolkata", "Mumbai", "Delhi"], " ");
    let B = join(["Geeks", "for", "Geeks"], "");
    let C = join(["Ram", "Shyam", "Geeks", "Rahim"], "+");
           
    // Set the size of text 
    textSize(16); 
       
    // Set the text color 
    fill(color('red')); 
     
    // Getting joined strings
    text("Joined string is: " + A, 50, 30);
    text("Joined string is: " + B, 50, 60);
    text("Joined string is: " + C, 50, 90);
} 


Output:

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS