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().

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 ...

Get Simplifying JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.