Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Two-Dimensional Arrays

Alex Franklin
Alex Franklin
12,398 Points

At 00:07:30:00, you say index "one - zero" returns "Respect," but isn't that TEN? Should it be, "ZERO/ONE" instead?

I'm super confused if this IS NOT a simple case where the presenter mis-spoke... You say the index value, [10], will return Aretha Franklin's, "R.E.S.P.E.C.T.." However, shouldn't it be the opposite?

I CANT FIGURE OUT HOW TO MARK BEST ANSWER AND CLOSE THIS, BUT THANK YOU DAVE THAT MAKES MUCH MORE SENSE AND I HAVE A BETTER UNDERSTANDING NOW:)

1 Answer

Dave StSomeWhere
Dave StSomeWhere
19,822 Points

Since it is a multi-dimensional (two) array, he is referring to two different indexes. Index 1 of the first array points to the second song and Index 0 of the inside array points to the song title. Two different sets of square braces.

two_dimension_array = [
    ['I did it my way', 'Frank Old Blue Eyes'],
    ['R.E.S.P.E.C.T', 'The Queen of Soul, Aretha'],
    ['Born to Run', 'The Boss, Bruce'],
    ['Imagine', 'John Lennon']
]

print("Index 1, 0 is --> " + two_dimension_array[1][0])
print("Index 0, 1 is --> " + two_dimension_array[0][1])

# outputs:
Index 1, 0 is --> R.E.S.P.E.C.T
Index 0, 1 is --> Frank Old Blue Eyes