Find closest object if object removed from list?

I created an array with a list of targets.

 GameObject[] target = GameObject.FindGameObjectsWithTag(enemyTag);
            foreach (GameObject go in target)
            {
                path.Add(go.transform);
            }

During the game, the player looks for the closest one.

int findClosestTarget()
    {
        if (path.Count == 0) return -1;     
            int closest = 0;
            float lastDist = Vector3.Distance(this.transform.position, path[0].position);
            for(int i = 1; i < path.Count; i++)
            {         
            float thisDist = Vector3.Distance(this.transform.position, path*.position);*

if(lastDist > thisDist && i != currentTarget)
{
closest = i;
lastDist = thisDist;
}
}

return closest;
}
But sometimes, one of those targets gets destroyed and I get an error message (NullReferenceException: Object reference no set to an instance…). I assume I have to remove it from the array so I tried the following both in Update and in the findClosestTarget function
if (path[currentTarget] = null)* *path.Remove(path[currentTarget]);
but that did not work and I keep getting the error message. What is the correct way of removing the destroyed target from the array?

There are two ways I can think of that use the same function (one being less intensive but more dangerous to implement)

The main function is a clean array function:

void CleanList(List<GameObject> objList)
    {
        for(var i = objList.Count - 1; i > -1; i--)
        {
            if (objList *== null)*

objList.RemoveAt(i);
}
}
You then can either call this function everytime you destroy an object part of this list or the easier method add it to the first line of your findClosestTarget void.

You can also use RemoveAll() method List<T> offers for more readblity :

path.RemoveAll(p=> !p);

reference