How to delete instantiated GameObject used in An Array

if ( i+1 < Items.Length)
Instantiate(Items[i++], transform.position, transform.rotation);
// How to delete the preceding object here?


Thank you.

you can always destroy an object in an array with Destroy(gameObject) but that does not shorten the array. in other words you will get a null reference at that index number which can cause errors.

lists can be a bit slower in some ways but have these options of removing things built in.
arrays do not.
if you want to use an array instead of a list here is a function :

public static GameObject[] RemoveAt (GameObject[] array,int IndexNumberToRemove){

            //delete the actual object from the scene like this;
				Destroy (array [IndexNumberToRemove]);

		// remove the empty slot in the array 
		int i = 0;
		GameObject[] ret = new GameObject[array.Length - 1];
		while (i<ret.Length) {
			int i2 = i;
			ret *= array[i2];	*
  •  	i++;*
  •  }*
  •  return ret;*
  • }*
    use this to call the function:
    // 3 is the the index number to remove in this example
    Items = RemoveAt(Items,3);

Thank you for your response. I appreciate it.
I am trying to call each object from Array by each mouse click, at the same time I need to remove the previous object from the scene. That is, when the object[1] is called, the object[0] is removed and so on.