Related Articles

Related Articles

p5.js TypedDict remove() Method
  • Last Updated : 27 Nov, 2020

The remove() method of p5.TypedDict in p5.js is used to remove the given key-value pair from the typed dictionary. A key-value pair is a set of two values that are mapped to each other. These values can be accessed by querying this dictionary using the key portion of the pair. A typed dictionary can store multiple key-value pairs that can be accessed using the methods of the dictionary.

Syntax: 

remove( key )

Parameters: This method accepts a single parameter as shown above and discussed below:

  • key: This is a string that denotes the key that has to be checked in the dictionary.

The example below illustrates the remove() method in p5.js:

Example:



Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

function setup() {
  createCanvas(550, 400);
  textSize(16);
  
  let tmpObj = {
    "Statue of Unity": "182 m",
    "Spring Temple Buddha": "128 m",
    "Ushiku Daibutsu": "100 m",
    "Great Buddha of Thailand": "92m"
  };
  
  // Create a new string dictionary
  let stringDict =
      createStringDict(tmpObj);
  text("New string dictionary created", 20, 20);
  
  // Checking the size of the dictionary
  let currSize = stringDict.size();
  text("The current size of the " +
       "dictionary is: " + currSize, 20, 40);
  
  let existOne =
      stringDict.hasKey("Statue of Unity");
  text("Dictionary has key " +
       "'Statue of Unity': " +
       existOne, 20, 80);
  
  let existTwo =
      stringDict.hasKey("Spring Temple Buddha");
  text("Dictionary has key " +
       "'Spring Temple Buddha': " +
       existTwo, 20, 100);
  
  // Removing one key
  stringDict.remove("Spring Temple Buddha");
  text("One key removed from the dictionary",
       20, 140);
  
  // Checking the size of the dictionary again
  currSize = stringDict.size();
  text("The current size of the dictionary is: " +
       currSize, 20, 160);
  
  // Checking for the removed key
  existTwo =
    stringDict.hasKey("Spring Temple Buddha");
  text("Dictionary has key " +
       "'Spring Temple Buddha': " +
       existTwo, 20, 200);
  
  // Checking the other keys
  let existThree = 
      stringDict.hasKey("Ushiku Daibutsu");
  text("Dictionary has key " +
       "'Ushiku Daibutsu': " +
       existThree, 20, 220);
}

chevron_right


Output:

Online editor: https://editor.p5js.org/
Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
Reference: https://p5js.org/reference/#/p5.TypedDict/remove

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :