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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。