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! While you're at it, check out some resources Treehouse students have shared here.
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 trialKristian Woods
23,414 PointsWhat 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?
Thanks
var list = [
{
name: "kris"
},
{
name: "bob"
},
{
name: "jon"
}
];
list.forEach(function(students) {
console.log(students.name);
});
Also, a side question is: is the forEach() an older method. Has it been replaced by each()...?
1 Answer
Steven Parker
231,269 PointsThe .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.
Jason Welsh
Treehouse Project ReviewerJason Welsh
Treehouse Project ReviewerCan you link those methods?