Thursday, November 13, 2025
HomeLanguagesJavascriptp5.js NumberDict minValue() Method

p5.js NumberDict minValue() Method

The minValue() method of p5.NumberDict in p5.js is used to find the lowest value in a number dictionary. A number dictionary can store multiple key-value pairs.

Syntax:

minValue()

Parameters: This method does not accept any parameters.

Return Value: It returns a Number value that is the lowest value in the dictionary.

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

Example:

Javascript




function setup() {
  createCanvas(550, 300);
  textSize(16);
  
  text("Click on the button to create a " +
       "new dictionary and get the lowest value",
       20, 20);
  
  setBtn = 
    createButton("Create random dictionary");
  setBtn.position(30, 40);
  setBtn.mouseClicked(createNewDict);
  
  getBtn = createButton("Get Lowest Value");
  getBtn.position(300, 40);
  getBtn.mouseClicked(getLowestValue);
}
  
function createNewDict() {
  clear();
  
  // Create an object with random values
  let obj = {};
  for (let i = 0; i < 5; i++) {
    let rk = ceil(Math.random() * 100);
    let rn = floor(Math.random() * 100);
    rn = (rk > 50) ? rn : -rn;
  
    obj[rk] = rn;
  
    text("Key: " + rk + " : Value: " + 
         rn, 40, 120 + 20 * i);
  }
  
  // Create a dictionary using the
  // above values
  numDict = createNumberDict(obj);
  
  text("New Dictionary created with values",
       20, 80);
  
  text("Click on the button to create a " +
       "new dictionary and get the lowest value",
       20, 20);
}
  
function getLowestValue() {
  
  // Get the lowest value in the dictionary
  let lowestVal = numDict.minValue();
  
  // Display the lowest value
  text("The lowest value in the dictionary is: " +
       lowestVal, 20, 240);
  
  text("Click on the button to create a " +
       "new dictionary and get the lowest value",
       20, 20);
}


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.NumberDict/minValue

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11916 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11983 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7141 POSTS0 COMMENTS
Thapelo Manthata
6835 POSTS0 COMMENTS
Umr Jansen
6839 POSTS0 COMMENTS