+ 9
Two dimensional array. How does it works?
I don't really understand
6 odpowiedzi
+ 11
@daemon you got it all right just a remark (not that I know better) indices in JavaScript starts at 0, so the element 3 would be arr[1][0] not arr[2][1]
+ 9
they are mostly used to represent points on a graph (x and y coordinates), vectors, matrices,... .when you use them in an array you get to manipulate them easily. use double pair of square brackets to select the item inside the array of arrays:
var a = [[1,2],[3,4]]
alert(a[1][0])
outputs 3 since the 2nd array has index 1 in a, and in it 3 occupies index 0
+ 8
Thanks ;-) I understand now
+ 2
Well, it's an array, except every element in the array is another array. For instance, this: [[1, 1, 2], [3, 5, 8], [13, 21, 34]].
Let's say you wanted to access the element "3" in that array. In that case, if the array's name is arr, we'd get arr[2][1].
Also, you've seen a matrix, right? It helps to think of 2D arrays as matrices. The above would be:
[ 1 1 2 ]
[ 3 5 8 ]
[ 13 21 34 ]
+ 2
@Hasan Fares Oh, that's right! Thanks for catching my mistake. :D
+ 2
it is simply an array of arrays. to access a value,
exampleArray[ ] [ ] the first [ ] being the parent array and the second [ ] the child.