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 trialFrancois Martin
1,958 PointsI don't understand where the index number comes from, it looks like its a cycle that is never set?
where does the index get set?
neilsood
4,991 PointsI believe the map function takes an optional index parameter corresponding to the index of the array it is mapping. So the players array has an implicit index based on its position in the array, which is then passed down.
Joshua Lucas
8,778 PointsThe index is the position of the player in the array. (I.e Guil's index is 0 because it is the first item in the array. )
1 Answer
Daniel Nakonieczny
Courses Plus Student 54,657 PointsThe JavaScript map function passes it automatically, we were just ignoring/not using it before:
this.state.players.map( (player) =>
and now:
this.state.players.map( (player, index) =>
Take a look at the map documentation here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
Seokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,606 PointsSeokhyun Wie
Full Stack JavaScript Techdegree Graduate 21,606 PointsDaniel Nakonieczny Greate answer. It's a shame that the answer is posted as a comment, I cannot give an upvote. Thanks.