How to get a value in an array based on the sampled value

It worked.
thanks for your help.