StylePropertyMapReadOnly: forEach() Methode
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Die StylePropertyMapReadOnly.forEach() Methode führt eine bereitgestellte Funktion einmal für jedes Element von StylePropertyMapReadOnly aus.
Syntax
js
forEach(callbackFn)
forEach(callbackFn, thisArg)
Parameter
callbackFn-
Die Funktion, die für jedes Element ausgeführt wird und drei Argumente annimmt:
currentValue-
Der Wert des aktuellen Elements, das verarbeitet wird.
indexOptional-
Der Index des aktuellen Elements, das verarbeitet wird.
arrayOptional-
Das StylePropertyMapReadOnly, auf dem
forEach()aufgerufen wird.
thisArgOptional-
Wert, der als
this(d.h. das ReferenzObject) verwendet wird, wenncallbackausgeführt wird.
Rückgabewert
Keine (undefined).
Beispiele
Hier ist ein Beispiel für die Verwendung von forEach() auf einem abgerufenen Element.computedStyleMap().
js
// get a button element
const buttonEl = document.querySelector(".example");
// we can retrieve all computed styles with `computedStyleMap`
const allComputedStyles = buttonEl.computedStyleMap();
// forEach will allow us to run code over each prop/val pair
allComputedStyles.forEach((elem, index, arr) => {
// code to run for each pair
});
Spezifikationen
This feature does not appear to be defined in any specification.>Browser-Kompatibilität
Loading…