p5.js | reverse() function

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

Syntax:

reverse(Array)

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

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 reverse() function.
        let Array3 = reverse(Array1);
        let Array4 = reverse(Array2);
      
    // Set the size of text 
    textSize(16); 
      
        // Set the text color 
    fill(color('red')); 
    
    // Getting new reversed array
    text("First reversed array is : "
      + Array3, 50, 30);
        text("Second reversed array is : " 
      + Array4, 50, 50);            

chevron_right


Output:

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.