forEach()
Performs an action for each element (does not produce output).
Syntax
arr.forEach(element => { ... })Description
Similar to map but does not return a new arr; just runs the job you provide for each element.
Example
Loading editor…
Expected output
a b
When to use?
Printing each element, side-effect operations.
Common mistakes
- ⚠️ Use map instead of forEach if you need a new arr.