KeyboardLayoutMap:entries() 方法

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

KeyboardLayoutMap 接口的 entries() 方法返回一个新的迭代器对象,该对象包含键/值对,顺序与 for...in 循环提供的顺序相同(不同之处在于 for-in 循环也会枚举原型链中的属性)。

该方法与 Map.prototype.entries() 相似。

语法

js
entries()

返回值

一个新的迭代器对象。

示例

以下示例迭代英文 QWERTY 键盘上每个位置或布局特定的字符串及其关联的键盘代码。

js
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => {
  for (const [code, key] of keyboardLayoutMap.entries()) {
    console.log(`键盘代码 ${code} 代表键 ${key}`);
  }
});

规范

Specification
ECMAScript® 2025 Language Specification
# sec-map.prototype.entries

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
entries
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.

参见