This code is going to remove all the 'b' elements out of the array. It does, but not entirely. There is still one 'b' left after the code is executed. Why is it happening? When we set the 3rd argument into splice method to change a 'b' element into another, it works well. But with only two arguments, does not. Why?
let array = ['a','b','c','b','d','e','d','b','b','b','d','d'];
var i = 0;
while (i < array.length){
if (array[i] === 'b'){
array.splice(i,1);
}
i++;
}
console.log(array);
ion each iteration, but when you remove a "b" you'll skip an extra character because removing that one makes the array shorter.