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 trialJames Steele
2,844 Pointsindex in arrays
In this video the index is used to loop through the objects in the array, previously it was used to loop through the arrays in the array. So an index can be used to loop through anything inside an array? Is this because an array is an object itself?
1 Answer
Steven Parker
231,275 PointsYes, an array is an object itself, but I'm not sure that relates to your question.
Regardless of what an array contains (objects, other arrays, numbers, strings, etc) you can use an index to get one specific item from the array. The index can be used in a loop to do something with each element of the array.
But arrays also have methods like "forEach", "map", and "reduce" which all can be used to do things with the array elements. So you have choices, depending on what it is you want to do.