Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Array Iteration Methods Array Iteration `for` vs forEach()


Why do we need to pass a parameter.Example

const numbers = [1, 2 , 3 ,4 , 5] 
numbers.forEach( number =>{


whats the point of the number word

1 Answer

Mark Sebeck
Mark Sebeck
Treehouse Moderator 30,295 Points

The foreach will call the callback function once for each element of the array numbers. As it iterates through the array number is the value of the current element in the array. So the first time it calls the call back function it will pass the first element (1) and the second time it will pass 2.

Here's a helpful link

Hope this help!