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 trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects Mixing and Matching Arrays and Objects

index 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
Steven Parker
229,785 Points

Yes, 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.