Hi there, 6 years from the future.
My current project involves creating an array of UI images and dragging and dropping them into other areas of the UI. I have found a solution that works for my project is the following:
Set the visibility of the item to collapse instead of forcefully removing the item from the array. This way works for me because I can update the array behind the scenes whenever the player leaves the UI, and keep each item in the array in its original index with no modifications to the loop.
Hope this helps someone in 2022.