Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten. Erfahre mehr über dieses Experiment.

View in English Always switch to English

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.

index Optional

Der Index des aktuellen Elements, das verarbeitet wird.

array Optional

Das StylePropertyMapReadOnly, auf dem forEach() aufgerufen wird.

thisArg Optional

Wert, der als this (d.h. das ReferenzObject) verwendet wird, wenn callback ausgefü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