How to find the closest value in an array?

I’m working on a large dataset. I want to find the closest value to my target value that helps me find outliers in my dataset. For this purpose, I wrote a code but it’s not very efficient. Can you provide me with other alternative methods that give me the same result that I want?

Luckily, my code is working fine but I’m searching for various methods of doing the same. Here’s my code below: