Open In App

p5.js append() function

Last Updated : 22 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The append() function in p5.js is used to add value at the end of a given array i.e, it increases the length of the original array by one.

Syntax:

append(Array, Value)

Parameters: This function accepts two parameters as mentioned above and described below:

  • Array: It is the original input array to which a new value to be added.
  • Value: It is the value which to be added at the end of the Array.

Return Value: It returns the new appended array.

Below program illustrates the append() function in p5.js:

Example: This example uses append() function to add any value at the end of the input array.




function setup() { 
   
    // Creating Canvas size
    createCanvas(550, 110); 
   
function draw() { 
       
    // Set the background color 
    background(220); 
       
    // Initialize the array into variables
    let a = ['IT', 'CSE', 'ECE'];
    let b = ['geeks', 'Students', 'Teachers'];
    let c = ['Delhi', 'Mumbai'];
       
    // Initialize the value into variables
    let v = 'Civil';
    let w = 'Peoples';
    let x = 'Kolkata';
     
    // Calling to append() function
    let p = append(a, v);
    let q = append(b, w);
    let r = append(c, x);
         
    // Set the size of text 
    textSize(16); 
       
    // Set the text color 
    fill(color('red')); 
     
    // Getting appended array
    text("First appended array is : " + p, 50, 30);
    text("Second appended array is : " + q, 50, 50);
    text("Third appended array is : " + r, 50, 70);          


Output:

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



Previous Article
Next Article

Similar Reads

ArrayObject append() function in PHP
The append() function of the ArrayObject class in PHP is used to append a given value onto an ArrayObject. The value being appended can be a single value or an array itself. Syntax: void append($value) Parameters: This function accepts a single parameter $value, representing the value to be appended. Return Value: This function does not returns any
1 min read
PHP | ArrayIterator append() Function
The ArrayIterator::append() function is an inbuilt function in PHP which is used to append an element into an array iterator. Syntax: void ArrayIterator::append( mixed $value ) Parameters: This function accepts single parameter $value that holds the value that need to be append. Return Value: This function does not return any value. Below programs
1 min read
PHP | AppendIterator append() Function
The AppendIterator::append() function is an inbuilt function in PHP which is used to append an iterator. Syntax: void AppendIterator::append( Iterator $iterator ) Parameters: This function accepts single parameter $iterator which holds the iterator to append. Return Value: This function does not return any value. Below programs illustrate the Appen
1 min read
Express.js res.append() Function
The res.append() function appends the specified value to the HTTP response header field and if the header is not already set then it creates the header with the specified value. Syntax: res.append(field [, value]) Parameter: The field parameter describes the name of the field that need to be appended and the value parameter can be a string or an ar
2 min read
D3.js selection.append() Function
The selection.append() function is used to append a new element to the HTML tag name as given in the parameters to the end of the element. If the type that is given is a function then it must be evaluated for each element that is in the selection. Syntax: selection.append(type); Parameters: This function takes only one parameter which is given abov
2 min read
How to append a new table row in AngularJS ?
In this article, we will see how to insert or append the new table row in AngularJS, along with knowing its implementation through the examples. Approach: The approach is to use the push() method to insert the new rows into the array. This array will be served as the content to the <tr> element. The ng-repeat directive is used to serve the co
2 min read
PHP append one array to another
Given two array arr1 and arr2 and the task is to append one array to another array. Examples: Input : arr1 = [ 1, 2 ] arr2 = [ 3, 4 ] Output : arr1 = [ 1, 2, 3, 4 ] Input : arr1 = [ "Geeks", "g4g" ] arr2 = [ "GeeksforGeeks" ] Output : arr1 = [ "Geeks", "g4g", "GeeksforGeeks" ] Using array_merge function: This function returns a new array after merg
2 min read
jQuery append() Method
The append() method in jQuery is used to insert some content at the end of the selected elements. Syntax: $(selector).append( content, function(index, html) ) Parameters: This method accepts two parameters as mentioned above and described below: content: It is a required parameter and is used to specify the content which is to be inserted at the en
2 min read
Node.js URLSearchParams.append()
In URLSearchParams interface, the append() method adds a key/value pair specified by user. Syntax: URLSearchParams.append(name, value) Parameters: name - Input the parameter name to append value - Input the parameter value to append Example1: let url = new URL('https://example.com?par=1&par1=3'); let params = new URLSearchParams(url.search.slic
1 min read
Implement Prepend and Append with Regular JavaScript
The task is to implement prepend() and append() methods using regular JavaScript. We're going to discuss a few methods. First few methods to know: JavaScript insertBefore() Method: This method inserts a node as a child, just before an existing child, which is specified. Syntax: node.insertBefore(newNode, existingNode) Parameters: newNode: This para
2 min read