it happens if you change the array you are iterating over
like, let’s say we have array [1,2,4,5,6,8] and we need to remove even numbers that are
index 0 - there is 1, it’s not even, it stays here
index 1 - there is 2, we need to remove this. Now the array is [1,4,5,6,8]
index 2 - there is 5, it’s not even, it stays here
index 3 - there is 6, we need to remove this. Now the array is [1,4,5,8]
index 4 - there isn’t an index 4, array ended. Result is [1,4,5,8]
do you notice what happened? the 4 went to index 1, which was already checked, so it was skipped. Same for the 8
i suggest that you use the for loop becoz the for…of loop is kinda complicated the apply the push method on those elements which aren’t in the array, happy coding camper!