why are you using a counter instead of enumerating the array with forEach(), or even filter()?