Help making algorythm

My problem may not be so connected with AS2 but the thing is that I am programing with AS2 so here goes my question:

I want to create an algorithm that looks up an array and finds the nearest integer in it. Lets say i have different numbers like 1, 2, 4, 5, 8, 9 and i want to find the nearest member to 6 from those numbers. How should i build the algorithm. So far iā€™m using two arrays and two inside loops, but cant find the right way to make it. :confused: So im am hoping for you kirupians to help me in any way. Thank you. :block: