How do i get my script to work?

i found a script to find the closest enemy and it works fine. but when the enemy is destroyed it doesn't remove the enemy out of the array. can someone help me please? here is the code im using:

var enemies : GameObject[];

function Update()
enemies = GameObject.FindGameObjectsWithTag("enemy"); 

if(enemies.length > 0) 
    target = enemies[0];
    var dist = Vector3.Distance(transform.position, enemies[0].transform.position);

    for(var i=0;i<enemies.length;i++) {
        var tempDist = Vector3.Distance(transform.position, enemies*.transform.position);*
 *if(tempDist < dist) {*
 _target = enemies*;*_
_*<p>i tried using:</p>*_
<em>_if (enemies *== null)*_</em>
<em>_*<p>but then it says that it isnt a member of unityengine.GameObject[].</p>*_</em>

The easiest way would probably to make your array static and then access it through your enemy script.

RemoveAt() isn't part of the array class. If I recall correctly (which I might not), you can swap the element that you want to remove with the first or last element of the array, and then use either shift() or pop() on it. shift() removes and returns the first element of an array, and pop() removes and returns the last.

I would give you some code, but I'm so rusty at JS that I'm afraid my code would probably be non-working.