p5.js shorten() function
Last Updated :
22 Aug, 2023
The shorten() function in p5.js is used to decrease the number of elements of the given array by one.
Syntax:
shorten(Array)
Parameters: This function accepts a parameter Array whose elements are to be shortened by one.
Return Value: It returns the shortened array.
Below program illustrates the shorten() function in p5.js.
Example-1:
function setup() {
createCanvas(500, 90);
}
function draw() {
background(220);
let Array1 = [ 'IT' , 'CSE' , 'ECE' ];
let Array2 = shorten(Array1);
textSize(16);
fill(color( 'red' ));
text( "Shortened array is : " + Array2, 50, 30);
}
|
Output:
Example-2:
function setup() {
createCanvas(500, 90);
}
function draw() {
background(220);
let Array = shorten([ 'Ram' , 'Shayam' , 'Geeta' , 'Anita' ]);
textSize(16);
fill(color( 'red' ));
text( "Shortened array is : " + Array, 50, 30);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/shorten
Share your thoughts in the comments
Please Login to comment...