Skip to content
Related Articles
Open in App
Not now

Related Articles

p5.js | reverse() function

Improve Article
Save Article
  • Last Updated : 10 Apr, 2019
Improve Article
Save Article

The reverse() function in p5.js is used to reverse the order of the given array element.



Parameters: This function accepts a parameter Array whose elements are to be reversed.

Return Value: It returns a new reversed array.

Below program illustrates the reverse() function in p5.js:
Example: This example uses reverse() function to reverse the order of the given array element.

function setup() { 
    // Creating Canvas size
    createCanvas(500, 90); 
function draw() { 
    // Set the background color 
    // Initializing the arrays
    let Array1 = ['IT', 'CSE', 'ECE'];
        let Array2 = ['Civil', 'Mechanical'];
        // Calling to reverse() function.
        let Array3 = reverse(Array1);
        let Array4 = reverse(Array2);
    // Set the size of text 
        // Set the text color 
    // Getting new reversed array
    text("First reversed array is : "
      + Array3, 50, 30);
        text("Second reversed array is : " 
      + Array4, 50, 50);            



My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!