Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Introduction to jQuery DOM Traversal Why We Traverse the DOM

What does the parameter in the JQuery forEach() method return?

I'm not sure what the returned value of the parameter is in the Jquery forEach() method

Could someone explain what is happening here?


var list = [
    name: "kris"
  name: "bob"
  name: "jon"

list.forEach(function(students) {

Also, a side question is: is the forEach() an older method. Has it been replaced by each()...?

1 Answer

Steven Parker
Steven Parker
228,026 Points

The .forEach method is part of JavaScript, it's not jQuery.

The first argument passed to the callback is the current array element. Optional second and third arguments are the element index and the array itself, respectively.

jQuery has two different .each methods, one works with arrays but the syntax is slightly different. The other is specifically for jQuery objects.