p5.js中p5.TypedDict的clear()方法用於刪除類型字典中的所有鍵值對。鍵值對是一組相互映射的兩個值。可以通過使用該對的關鍵字部分查詢此字典來訪問這些值。一個類型化的字典可以存儲可以使用字典方法訪問的多個鍵-值對。
用法:
clear()
參數:此方法不接受任何參數。
以下示例說明了p5.js中的clear()方法:
例:
Javascript
function setup() { 
  createCanvas(550, 500); 
  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 dictionary 
  let stringDict = 
      createStringDict(tmpObj); 
  text("New string dictionary created " + 
       "with four keys", 20, 40); 
  
  // Check for a key 
  let existOne =  
      stringDict.hasKey('Spring Temple Buddha'); 
  text("Dictionary has key " + 
       "'Spring Temple Buddha':" + 
       existOne, 20, 80); 
  
  // Check the current size 
  let currSize = stringDict.size(); 
  text("Current size of the dictionary:" + 
       currSize, 20, 100); 
  
  // Clear the dictionary 
  stringDict.clear(); 
  text("Dictionary has been cleared!", 
       20, 140); 
  
  // Check for a key again 
  existOne = 
    stringDict.hasKey('Spring Temple Buddha'); 
  text("Dictionary has key " + 
       "'Spring Temple Buddha':" + 
       existOne, 20, 180); 
  
  // Check the current size again 
  currSize = stringDict.size(); 
  text("Current size of the dictionary:" + 
       currSize, 20, 200); 
}輸出:

在線編輯: https://editor.p5js.org/
環境設置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
參考: https://p5js.org/reference/#/p5.TypedDict/clear
相關用法
- p5.js TypedDict set()用法及代碼示例
 - p5.js TypedDict get()用法及代碼示例
 - p5.js TypedDict create()用法及代碼示例
 - p5.js TypedDict hasKey()用法及代碼示例
 - p5.js TypedDict size()用法及代碼示例
 - p5.js TypedDict print()用法及代碼示例
 - p5.js TypedDict remove()用法及代碼示例
 - HTML DOM console.clear()用法及代碼示例
 - Node.js console.clear()用法及代碼示例
 - ASP Clear用法及代碼示例
 - Javascript Map.clear( )用法及代碼示例
 - PHP Imagick clear()用法及代碼示例
 - PHP Ds\Collection clear()用法及代碼示例
 - CSS clear屬性用法及代碼示例
 - PHP Ds\Vector clear()用法及代碼示例
 - PHP Gmagick clear()用法及代碼示例
 - PHP Ds\Set clear()用法及代碼示例
 - PHP Ds\Deque clear()用法及代碼示例
 - HTML Style clear用法及代碼示例
 - p5.js clear()用法及代碼示例
 
注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 p5.js TypedDict clear() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
