You’d have to traverse the whole array, then I would store the closest value in a variable.

func closest(my_number:int, my_array:Array)->int:
# Initialize
var closest_num:int
var closest_delta:int = 0
var temp_delta:int = 0
# Loop through entire array
for i in range(my_array.size()):
if my_array[i] == my_number: return my_array[i] # exact match found!
temp_delta = int(abs(my_array[i]-my_number))
if closest_delta == 0 or temp_delta < closest_delta:
closest_num = my_array[i]
closest_delta = temp_delta
# Return closest number found
return closest_num

Something like the above should get you close to what you want.