p5.js中p5.TypedDict的print()方法用於將當前存在於字典中的所有鍵值對輸出到控製台。鍵值對是一組相互映射的兩個值。可以通過使用該對的關鍵字部分查詢此字典來訪問這些值。一個類型化的字典可以存儲可以使用字典方法訪問的多個鍵/值對。
用法:
print()
參數:此方法不接受任何參數。
以下示例說明了p5.js中的print()方法:
例:
Javascript
function setup() {
createCanvas(550, 300);
textSize(16);
let stringDict =
createStringDict("Tokyo", "37.26 million");
text("New string dictionary created " +
"with one key", 20, 20);
// Getting the current size of the dictionary
let currSize = stringDict.size();
print("Printing " + currSize +
" key-value pair(s):");
// Printing all the values to console
stringDict.print();
text("Dictionary keys printed to console",
20, 60);
let tmpObj = {
"Delhi":"25.87 million",
"Shanghai":"23.48 million",
"Mexico City":"21.34 million"
};
// Add the given key to the dictionary
// specifying the key and value as an object
stringDict.create(tmpObj);
text("New keys added to the dictionary",
20, 100);
// Getting the current size of the dictionary
currSize = stringDict.size();
print("Printing " + currSize +
" key-value pair(s):");
// Printing all the values to console
stringDict.print();
text("Dictionary keys printed to console",
20, 140);
}
輸出:
在線編輯: https://editor.p5js.org/
環境設置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
參考: https://p5js.org/reference/#/p5.TypedDict/print
相關用法
- 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 remove()用法及代碼示例
- Javascript Window print()用法及代碼示例
- p5.js print()用法及代碼示例
注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 p5.js TypedDict print() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。