You have 2 different problem to fix:
1- you are modifying the array object in your for loop, after the first splice
the array is changed and the arr.length
is totally different for the rest of your loop items, to prevent it create a variable like len
and set it to the length of your array once.
but if you change the loop the other way round, you would need it once:
for(var i = arr.length; i >= 0; i--) {
if(arr[i] == cls) {
alert(arr[i - 1]);
var splCout = arr.splice(arr[i - 1], 1);
alert(splCout);
}
}
2- the next and the more important problem is the indexes of the array, when you remove an index the other indexes change (i......n) and the code won't work properly, but as you see when you iterate the array this way even when you remove the index, the other indexes back to the zero (i....0) don't change.