You could do it with a second array we'll call "list" and has a size of (0,3,1).
So you'd first loop over your array and check if any spot is equal to that certain value. If it is then make the list one longer and store the distance, and the current x and y in the array.
After that use the sort action on list and the first value will be the closest and the last will be the furthest.
Every tick
--- set list size to (0,3,1)
Array: for each xy
Array: current value=certainValue
--- list push 0 front
--- set list at (0,0) to distance(X,y, array.curx, array.cury)
--- set list at (0,1) to array.curx
--- set list at (0,2) to array.cury
Every tick
--- list: sort
Then the closest X and y would be:
List.at(0,1)
List.at(0,2)
And the furthest:
List.at(list.width-1,1)
List.at(list.width-1,2)