Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed JavaScript Array Iteration Methods!
You have completed JavaScript Array Iteration Methods!
Preview
Let's take a look at the forEach() `index` and `array` parameters.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Let's go the MDN documentation page for
the forEach method.
0:00
You can see here that the callback in
forEach actually accepts some other
0:00
parameters besides the array
element we've been using.
0:04
The second parameter will hold
the index of the current element.
0:08
So if the current value
is the first element, for
0:12
example, the index value will be zero.
0:15
If it's the second element
the index will be one, and so on.
0:18
If your code relies on the position
of the elements in an array,
0:22
this can be helpful to know.
0:26
The third parameter will
hold the whole array itself.
0:28
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up