files/en-us/web/api/keyboardlayoutmap/foreach/index.md
{{APIRef("Keyboard API")}}{{SeeCompatTable}}
The forEach() method of the
{{domxref('KeyboardLayoutMap')}} interface executes a provided function once for
each element of the map.
The method is otherwise the same as {{jsxref("Map.prototype.forEach()")}}.
forEach(callbackFn)
forEach(callbackFn, thisArg)
callbackFn
currentValue
index {{optional_inline}}
array {{optional_inline}}
forEach() is being called on.thisArg {{Optional_inline}}
this (i.e., the reference
Object) when executing callback.None ({{jsxref("undefined")}}).
The following example iterates every location- or layout-specific string and its associated keyboard code on an English QWERTY keyboard.
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => {
keyboardLayoutMap.forEach((key, code) => {
console.log(`${code} keyboard code represents ${key} key`);
});
});
{{Specifications}}
{{Compat}}