+ 2

Can you make a 2+ dimensional array in JavaScript?

I know you can do such with C++, but nothing was said as to if it is possible to make such an array with Java Script.

28th Jul 2018, 11:21 PM
Sauron
Sauron - avatar
10 Antworten
+ 4
mArr[12][3] and mArr[1][23] are completely different, distinct expressions... The first one access the 13th element of mArr, and then retrieve the fourth object stored within that element. The second one access the second element of mArr, and then retrieve the 24th object stored within that element. It is impossible for the program to misinterpret (mArr[12])[3] as (mArr[1])[23]
29th Jul 2018, 5:01 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
Multidimensional arrays in JavaScript are arrays within arrays (within arrays within... ). var mArr = [ [3, 5], [2, 4] ]
29th Jul 2018, 12:15 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
2+ dimensional arrays, or multidimensional arrays, are just arrays within arrays. An N-dimensional array is such that the deepest array within the multidimensional array is like N "layers" into it.
29th Jul 2018, 12:26 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
var mArr = [[3,5],[2,4]] console.log(mArr[0][1]) // 5 console.log(mArr[1][0]) // 2 The language has well-defined standards. Your program won't just "confuse" itself. Also, it would help if you condense your reply as one post. It's a forum, not a chat.
29th Jul 2018, 2:58 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
This code uses a 2d array(lines 118 - 127): https://code.sololearn.com/WyNZ0f7CAGA0/?ref=app
30th Jul 2018, 6:29 PM
Haris
Haris - avatar
0
okay, but let's say you have ten or more items in one or more of those arrays, so if to get a particular point in the array... Let's say 5 with the first array, and 23 with the second. Might the program possibly confuse it with array point 52 , 3? Or am I looking at this wrong?
29th Jul 2018, 2:31 AM
Sauron
Sauron - avatar
0
There.
29th Jul 2018, 3:03 AM
Sauron
Sauron - avatar
0
Okay, that is not what I am referring to. let's go with what you said earlier... var mArr = [[3,5,7,9,11,13...],[2,4,6,8,10,12,14...]] /*Imagine it being much longer...*/ /*Could the computer confuse*/ console.log(mArr[12][3]) /*with*/ console.log(mArr[1][23]) ???
29th Jul 2018, 3:08 AM
Sauron
Sauron - avatar
0
As in, mArr seeing them both as array point 123.
29th Jul 2018, 3:19 AM
Sauron
Sauron - avatar
0
^/^^ Okay, that makes sense. Thanks for the help.
29th Jul 2018, 1:47 PM
Sauron
Sauron - avatar