Tip 24: Apply Consistent Actions with forEach()

In this tip, you’ll learn how to apply an action to each member of an array with forEach().

Operations on the array values

Things are going to get a little different in this tip. The two array methods you’ve explored so far return a new, altered array. You either changed the shape by pulling out a subset of information on each item, or you changed the size by returning only part of the total number of items.

In this tip, you aren’t changing the input array at all. Instead, you’re going to perform an action on every member. This is common when you finally get an array to the size and shape you want and then you want to do something with that data.


As an example, say you have a club with a group of members and you want to write a script to send an invitation to every club member when the next meeting is scheduled. You want a function that takes each member individually so that you can use other information—name, email, and so on—to customize the message. Here’s a list of members:

Get hands-on with 1200+ tech skills courses.