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 trialBen Myhre
28,726 PointsIsn't "A two-dimensional array is an array of objects." TRUE?
It says it is false, and I get where they are going. A two dimensional array is an array of arrays, BUT a js array IS a javascript object, right? So a two dimensional array, really is an array of objects... making the answer, technically, TRUE... or that is how I read it.
2 Answers
Iain Diamond
29,379 PointsPerhaps, a graphical example might help:
1D array - position is denoted by x
1234567890
2D array, position is denoted by x, y
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
iain
Colin Marshall
32,861 PointsI think you missed his point. An array is an object in JavaScript, so since a two dimensional array is an "array of arrays," it is technically also an array of objects.
Iain Diamond
29,379 PointsThinking logically, this obviously is false:
- A 1D array is a list of objects.
- A 2D array is an array of arrays.
- However, an array is also an object.
- Therefore, a 2D array is an array of objects.
- Ergo, a 2D array is a 1D array.
Alternatively,
- A 1D array is a list of objects.
- A 2D array is an array of arrays.
- Or a 2D array is an array of a list of objects.
- Also, a list of objects is not the same as a simple object.
- Therefore a 2D array is not the same as a 1D array.
iain
Colin Marshall
32,861 PointsI see what you are getting at, but Array - Javascript | MDN says differently about arrays.
The JavaScript Array global object is a constructor for arrays, which are high-level, list-like objects.
To me, a "list-like object" is not the same thing as a "list of objects."
Ben Myhre
28,726 PointsI see it differently and I think the console does too.
Iain Diamond
29,379 PointsApparently, not all objects are equal.
> var a = [1,2,3,4,5]
undefined
> typeof(a)
'object'
> typeof(a[0])
'number'
> typeof(a[0][0])
'undefined'
> b=[a,a]
[ [ 1, 2, 3, 4, 5 ], [ 1, 2, 3, 4, 5 ] ]
> typeof(b)
'object'
> typeof(b[0])
'object'
> typeof(b[0][0])
'number'
Colin Marshall
32,861 PointsColin Marshall
32,861 PointsI agree with your reasoning here. Maybe Dave McFarland can step in and explain this one for us.