Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Loop through the array and invoke the callback with (element, index, array) for each item. Unlike map, forEach returns undefined and is used purely for side effects. The implementation does not collect return values.
forEach provides a cleaner syntax than a for loop for executing side effects on each element. It always iterates the entire array and cannot be short-circuited with break or return.
Updated Feb 2026