Question: So I have a code running with something like this:

```
maxRow = 5

For numRow=1 to maxRow

    If Range("A" & numRow).Value = 0 Then

        Rows(numRow).Select

        Selection.Delete Shift:=xlUp

        numRow = numRow - 1 

        maxRow = maxRow - 1 

    End If

Next numRow

```

and I have 

> 
> A1 to A5 = 4 0 3 1 9 (respectively)
> 
> 
> 

yet for some reason the loop keeps going 

Anyone please help me so I end up with A1=4, A2=3, A3=1 and A4=9 without continuous looping.

Answer: 
One option is to use the [optional second argument to indexOf](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) to find duplicate indexes. Consider that for a given element `e` and an index `i`:

1. if `e` is the first of two identical elements in the array, `indexOf(e)` will return `i` and `indexOf(e, i + 1)` will return the index of the second element.
2. if `e` is the second of two identical elements in the array, `indexOf(e)` will return the index of the first element, and `indexOf(e, i + 1)` will return `-1`
3. if `e` is a unique element, `indexOf(e)` will return `i` and `indexOf(e, i + 1)` will return `-1`.

Therefore:

```
myArr.filter(function (e, i, a) {
  return a.indexOf(e) === i && a.indexOf(e, i + 1) === -1
});

```
```
var isUnique = function(v,i,arr){
   // return true if the first occurrence is the last occurrence 
   return ( arr.indexOf(v) === arr.lastIndexOf(v) ); 
};

var uniqueVals = myArr.filter(isUnique);

console.log( uniqueVals );

```