Search⌘ K
AI Features

forEach

Explore the JavaScript forEach method to understand its unique role in performing side effects on array elements. Learn how it contrasts with map and filter by not returning new arrays but instead affecting external variables, helping you write clearer and intentional code.

forEach

Array.forEach is different from map & filter. You may find it easier to reason about. map & filter return us new, altered arrays based off of the original array. forEach returns us undefined. It’s used purely to do something with the items in an array, not to get a new array out of it.

Here’s an example. The following two code blocks are ...