NodeList.forEach() calls your callback once for each node, in insertion order (MDN). It returns undefined — use it for side effects, not to build a new list.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call nodeList.forEach. Start with this line.
JavaScript
nodeList.forEach(callback, thisArg?)
Call
What it does
nodeList.forEach(callback, thisArg?)
Primary signature.
nodeList.forEach(...)
Call with the arguments your case needs.
Built into the browser. Call forEach(...) on a NodeList — no import required.
NodeList.forEach() is marked Baseline Widely available on MDN (since October 2017). DOM API — not a Node.js built-in.
✓ Baseline · Widely available
forEach()
Run a callback for each node in a NodeList across modern browsers.
98%Core tag support
Chrome51+
Full support
Edge16+
Full support
Firefox50+
Full support
Safari10+
Full support
Opera38+
Full support
HTML element100% supported
Bottom line: Safe for production. Prefer forEach for simple callbacks; use for...of / entries() when you need break.
Frequently Asked Questions
It calls your callback once for each node in the NodeList, in insertion order. The callback receives currentValue (the node), currentIndex, and the list itself.
No. MDN marks NodeList.forEach() as Baseline Widely available (since October 2017). It is not Deprecated, Experimental, or Non-standard.
undefined. It runs side effects in the callback; it does not build a new list.
An optional second argument used as this inside the callback when you pass a regular function. Arrow functions do not bind their own this, so thisArg has no effect with arrows.
forEach() runs a callback immediately for each node. entries() returns a lazy iterator of [index, node] pairs for for...of or Array.from.
No convenient break. Use for...of (optionally with entries()) or a classic for loop when you need to stop early.