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

No specification found

No specification data found for api.StylePropertyMapReadOnly.forEach.
Check for problems with this page or contribute a missing spec_url to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser-Kompatibilität