p5.js reverse() function
Last Updated :
22 Aug, 2023
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.
function setup() {
createCanvas(500, 90);
}
function draw() {
background(220);
let Array1 = [ 'IT' , 'CSE' , 'ECE' ];
let Array2 = [ 'Civil' , 'Mechanical' ];
let Array3 = reverse(Array1);
let Array4 = reverse(Array2);
textSize(16);
fill(color( 'red' ));
text( "First reversed array is : "
+ Array3, 50, 30);
text( "Second reversed array is : "
+ Array4, 50, 50);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/reverse
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...