files/en-us/web/api/stylepropertymapreadonly/foreach/index.md
{{APIRef("CSS Typed Object Model API")}}
The StylePropertyMapReadOnly.forEach() method executes a
provided function once for each element of {{domxref('StylePropertyMapReadOnly')}}.
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")}}).
Here is an example of using forEach() on a retrieved
{{domxref('Element.computedStyleMap()')}}.
// 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
});
{{Specifications}}
{{Compat}}