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 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,160 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,160 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