how does X array know idx==k values to be transferred to corresponding centroids. here is idx is keyword . I did not understand ,please help me to understand

While in exercise 1, in instructions it is mentioned to find_closest_centroids.
the function take the data matrix C and the locations of all centroids.
It should output a one-dimensional array idx (which has the same number of elements as X) that holds the index of the closest centroid (a value in {0,…,𝐾−1}, where 𝐾 is total number of centroids) to every training example . (Note: The index range 0 to K-1 varies slightly from what is shown in the lectures (i.e. 1 to K) because Python list indices start at 0 instead of 1)

So you using I ==k would be incorrect inclusion of all data points in data matrix with inclusion one dimension array, hence idx==k is correct