Thank you very much Mauro ! searchsorted is the simplest solution and one of the fastest but it gives two indices so another comparison is needed to find the closest value :
@time searchsorted(x, 8.22) 0.000004 seconds (7 allocations: 240 bytes) 74:73 abs(x[73] - 8.22) > abs(x[74] - 8.22) ? i = 74 : i = 73 73
