# Finding the "coords" (x,y) position of an item in a multidimensional array

**URL:** <https://forum.kirupa.com/t/finding-the-coords-x-y-position-of-an-item-in-a-multidimensional-array/217761>\
**Category:** Uncategorized\
**Created:** [March 1, 2007, 6:42pm UTC](https://forum.kirupa.com/t/finding-the-coords-x-y-position-of-an-item-in-a-multidimensional-array/217761 "2007-03-01T18:42:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kingscooty](https://avatars.discourse-cdn.com/v4/letter/k/73ab20/32.png) [@kingscooty](https://forum.kirupa.com/u/kingscooty)\
**Post date:** [March 1, 2007, 6:42pm UTC](https://forum.kirupa.com/t/finding-the-coords-x-y-position-of-an-item-in-a-multidimensional-array/217761/1 "2007-03-01T18:42:08Z")

</div>

Is there a relatively easy way of finding the x,y position of an item in a multidimensional grid array?

I have this grid structure for drawing a map for a game. Number 2 is going to be the starting point of the player. How would i find the x,y position of that number in the array?

It’s currently at 2,2 within the array… but i want it to be dynamic.

[AS]  
map[0] = new Array(1,1,1,1,1,1,1,1,1,1)  
map[1] = new Array(1,0,0,0,0,1,0,0,0,1)  
map[2] = new Array(1,0,2,0,1,0,0,0,1,1)  
map[3] = new Array(1,0,0,1,1,1,0,1,1,1)  
map[4] = new Array(1,0,0,0,1,0,0,0,1,1)  
map[5] = new Array(1,0,0,0,0,0,0,0,0,1)  
map[6] = new Array(1,1,1,1,0,1,1,1,1,1)  
map[7] = new Array(1,0,0,0,0,0,0,0,0,1)  
map[8] = new Array(1,0,0,0,0,0,0,0,0,1)  
map[9] = new Array(1,1,1,1,1,1,1,1,0,1)  
[/AS]

This is the code i have to draw the map.

[AS]  
function drawIt(theMap) {  
var pos = 0;  
diameter = 72;  
xOffset = 20;  
yOffset = 15;  
for (var y = 0; y\<diameter; y++) {  
for (var x = 0; x\<diameter; x++) {  
pos = x+(y_diameter);  
if (theMap[y][x] == 0) {  
 root.attachMovie(“myTile2”, "tile"+pos, pos, {\_x:x_diameter+xOffset, \_y:y_diameter+yOffset});  
} else if (theMap[y][x] == 1) {  
 root.attachMovie(“myTile”, "tile"+pos, pos, {\_x:x_diameter+xOffset, \_y:y_diameter+yOffset});  
} else if (theMap[y][x] == 2) {  
\_root.attachMovie(“sprite”, “sprite”, 2, {\_x:x_diameter+xOffset+35, \_y:y\*diameter+yOffset+35});  
}  
}  
}  
}  
[/AS]
