KeyboardLayoutMap: phương thức keys()

Limited availability

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

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Phương thức keys() của giao diện KeyboardLayoutMap trả về một đối tượng Iterator mới chứa các khóa cho mỗi chỉ mục trong đối tượng KeyboardLayoutMap.

Phương thức này giống với Map.prototype.keys().

Cú pháp

js
keys()

Tham số

Không có.

Giá trị trả về

Một đối tượng Iterator mới.

Ví dụ

Ví dụ sau lặp qua mỗi mã bàn phím trên bàn phím QWERTY tiếng Anh.

js
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => {
  for (const code of keyboardLayoutMap.keys()) {
    console.log(`${code} keyboard code`);
  }
});

Thông số kỹ thuật

Specification
ECMAScript® 2027 Language Specification
# sec-map.prototype.keys

Tương thích trình duyệt

Xem thêm