just insert a line like this at the start of the loop:
for(int i = 0; i < array.Length; i++) {
if(array *== null) {*
continue; } //whatever you want to do if there’s actually something stored in this position }
or, with a foreach loop: foreach(GameObject go in array) { if(go == null) { continue; } //whatever you want to do if there’s actually something stored in this position } This will skip all the following code inside the loop and go on with the next array element.
If you’re using C# you could use a HashSet. It both allows you to do a foreach, and also to Add and Remove elements with reasonable speed. An array is probably not the best choice for something which grows and shrinks dynamically.