p5.js中p5.TypedDict的remove()方法用於從類型化字典中刪除給定的鍵值對。鍵值對是一組相互映射的兩個值。可以通過使用該對的關鍵字部分查詢此字典來訪問這些值。一個類型化的字典可以存儲可以使用字典方法訪問的多個鍵-值對。
用法:
remove( key )
參數:此方法接受單個參數,如上所示和以下討論:
- key:這是一個字符串,表示必須在字典中檢查的鍵。
以下示例說明了p5.js中的remove()方法:
例:
Javascript
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);
}
輸出:
在線編輯: https://editor.p5js.org/
環境設置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
參考: https://p5js.org/reference/#/p5.TypedDict/remove
相關用法
- p5.js TypedDict set()用法及代碼示例
- p5.js TypedDict get()用法及代碼示例
- p5.js TypedDict create()用法及代碼示例
- p5.js TypedDict hasKey()用法及代碼示例
- p5.js TypedDict clear()用法及代碼示例
- p5.js TypedDict size()用法及代碼示例
- p5.js TypedDict print()用法及代碼示例
- HTML DOM Select remove()用法及代碼示例
- Lodash _.remove()用法及代碼示例
- jQuery callbacks.remove()用法及代碼示例
- ASP Contents.Remove用法及代碼示例
- PHP Ds\Vector remove()用法及代碼示例
- PHP Ds\Vector remove()用法及代碼示例
注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 p5.js TypedDict remove() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。