StylePropertyMapReadOnly: forEach() 方法

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

StylePropertyMapReadOnly.forEach() 方法對 StylePropertyMapReadOnly 的每個元素執行一次提供的函式。

語法

js
forEach(callbackFn)
forEach(callbackFn, thisArg)

引數

callbackFn

要為每個元素執行的函式,接受三個引數

currentValue

正在處理的當前元素的值。

index 可選

正在處理的當前元素的索引。

array 可選

呼叫 forEach() 的 StylePropertyMapReadOnly。

thisArg 可選

執行 callback 時用作 this(即引用 Object)的值。

返回值

無(undefined)。

示例

這是一個在檢索到的 Element.computedStyleMap() 上使用 forEach() 的示例。

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
});

規範

此特性似乎未在任何規範中定義。

瀏覽器相容性