HELP unsetting array element in loop

I have a loop and I need to be able to unset the array element that I am currently accessing in it. I was thinking of making a counter that increments with the loop and doing unset $dirs[$counter] but if I do that I am not sure if the other members of the array would get shifted down in index (meaning that the second time I unset an element I would unset the element in front of the one that I actually want to unset).

Any help is appreciated.

for x in ${dirs[@]}
do
if [[ $x == $dir* ]]; then
bool=1
# here I need to do unset $dirs[????]....
fi
done

I don't know if this is an option for you, but you could create another array and store the counter values (array postions which need to be deleted) and do the unset thing in a second for loop when the first for loop ends.

You can scan the array this way, so you have the index :

for ((i=0; i<${#dirs[@]}; i++))
do
    if [[ ${#dirs[$i]} == $dir* ]]
    then
        bool=1
        # here I need to do unset $dirs[????]....
        ${#dirs[$i]}=""
    fi
done