this would be a lot easier to talk about if you had code to share instead of screenshots, but what's probably happening is that you're removing elements, which is shifting the index of the remaining elements, or at least something similar.
If you want to remove all the elements you can do this
takes any number of arguments, and removes each from the classlist. the takes the array-like DOMTokenList and spreads it out into individual arguments that get passed to