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 Build a Quiz Challenge, Part 1

Two Dimenstional Arrays

what does the Array.length property returns in case of 2d arrays i know it returns the length but it is a bit confusing could some one explain please ?

5 Answers

Balazs Peak
Balazs Peak
46,121 Points

Think of it like this: multi dimensional arrays are actually not multi dimensional, they are just "recursive".

A 2 dimensional array is an array of arrays. A 3 dimensional array is an array of arrays of arrays ... etc.

The length property returns the outer-most dimension's length.

Balazs Peak
Balazs Peak
46,121 Points

It will return the length of the first dimension.

I've made a demonstration with a 2 dimensional and a 1 dimansional array, check it out:

http://rextester.com/LKGB89866

the first dimension is the row you mean ??

Aha Thanks a lot i got it