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

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 entries() của giao diện KeyboardLayoutMap trả về một đối tượng Iterator mới chứa các cặp khóa/giá trị, theo cùng thứ tự do vòng lặp for...in cung cấp (sự khác biệt là vòng lặp for-in cũng liệt kê các thuộc tính trong chuỗi prototype).

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

Cú pháp

js
entries()

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 chuỗi theo vị trí hoặc bố cục cụ thể và mã bàn phím liên kết của nó trên bàn phím QWERTY tiếng Anh.

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

Thông số kỹ thuật

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

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

Xem thêm