KeyboardLayoutMap: entries() 方法
KeyboardLayoutMap 介面的 entries() 方法返回一個新的 Iterator 物件,其中包含鍵/值對,其順序與 for...in 迴圈提供的順序相同(區別在於 for-in 迴圈還會列舉原型鏈中的屬性)。
該方法在其他方面與 Map.prototype.entries() 相同。
語法
js
entries()
引數
無。
返回值
一個新的 Iterator 物件。
示例
以下示例迭代了英語 QWERTY 鍵盤上的每個位置或佈局特定的字串及其關聯的鍵盤程式碼。
js
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => {
for (const [code, key] of keyboardLayoutMap.entries()) {
console.log(`${code} keyboard code represents ${key} key`);
}
});
規範
| 規範 |
|---|
| ECMAScript® 2026 語言規範 # sec-map.prototype.entries |
瀏覽器相容性
載入中…