p5.js shorten() function Read Discuss Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue Report 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() { // Creating Canvas size createCanvas(500, 90); } function draw() { // Set the background color background(220); // Initializing the arrays let Array1 = ['IT', 'CSE', 'ECE']; // Calling to shorten() function. let Array2 = shorten(Array1); // Set the size of text textSize(16); // Set the text color fill(color('red')); // Getting new shortened array text("Shortened array is : " + Array2, 50, 30); } Output: Example-2: function setup() { // Creating Canvas size createCanvas(500, 90); } function draw() { // Set the background color background(220); // Calling to shorten() function on an array // Taken as the parameter let Array = shorten(['Ram', 'Shayam', 'Geeta', 'Anita']); // Set the size of text textSize(16); // Set the text color fill(color('red')); // Getting new shortened array text("Shortened array is : " + Array, 50, 30); } Output: Reference: https://p5js.org/reference/#/p5/shorten Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks 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! Last Updated : 22 Aug, 2023 Like Article Save Article Previous p5.js fullscreen() function Next AngularJS angular.toJson() Function Please Login to comment...