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 trialSahan Balasuriya
10,115 Pointshow to parameter student.name work
var students = [
{ name: "Maddy" },
{ name: "Adam" },
{ name: "Jeseekia" }
];
students.forEach(function(student) {
console.log(student.name);
});
im not sure how the parameter student works and how does it know to get the name of the student from the students array
1 Answer
Nicholas Grenwalt
46,626 PointsSince you attached the .forEach method to the array of students what it does is go through each item in that array one by one doing whatever you tell it to do in the callback function. So basically in your mind picture that student param as that first student object in your students array. Heck, name it that to picture exactly what forEach is doing if it is helpful. Now in that callback you are simply just accessing that student object like how you would any other in dot notation and then logging it to the console. The forEach loop will then go to the next student object and so on until there are no more items left in the array.
Sahan Balasuriya
10,115 PointsSahan Balasuriya
10,115 Pointsthanks I sort of understand it now