Higher Order Functions

Implement forEach

Implement forEach

Writing a small forEach helper makes its side-effect contract explicit. The helper should call the callback once for each item, in order, and it should not collect callback return values.

That ignored return value is the point. Code that uses forEach should rely on side effects inside the callback, not on the helper returning a transformed array.

Your task: Complete customForEach so it calls the callback with item, index, and original array for every item. Return undefined, and do not use the built-in .forEach() method inside your implementation.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Implement forEach

Writing a small forEach helper makes its side-effect contract explicit. The helper should call the callback once for each item, in order, and it should not collect callback return values.

That ignored return value is the point. Code that uses forEach should rely on side effects inside the callback, not on the helper returning a transformed array.

Your task: Complete customForEach so it calls the callback with item, index, and original array for every item. Return undefined, and do not use the built-in .forEach() method inside your implementation.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Console

Run code to see output.