+ 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.
10 ответов
+ 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]
+ 3
Multidimensional arrays in JavaScript are arrays within arrays (within arrays within... ).
var mArr = [ [3, 5], [2, 4] ]
+ 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.
+ 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.
+ 2
This code uses a 2d array(lines 118 - 127):
https://code.sololearn.com/WyNZ0f7CAGA0/?ref=app
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?
0
There.
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])
???
0
As in, mArr seeing them both as array point 123.
0
^/^^
Okay, that makes sense. Thanks for the help.