Reputation: 469
I have an array like this:
0 1 2
3 4 5
6 7 8
these numbers are indices of this array
this array has been initialized with:
1,1 3,1 5,1
1,3 3,3 5,3
1,5 3,5 5,5
which these numbers are the coordinate of the grid(the value inside my array). so my question is that, what should i do if i want to retrieve the value of one cell by it's index, for example if i call a method like getValue(5); the result would be 5,3. i know how to get the value in multi dimentional array but i don't know how to get taht with it's index.
Thank you
Upvotes: 1
Views: 41
Reputation: 595
yourArray[5]
gives a one dimensional array containing 5 and 3.
Edit: To address your comment.
function customIndex(int i) {
return myArray[Math.floor(i/3)][i%3];
}
Upvotes: 1