I am trying to remove items from an array. But i have to do it from each item from it. For that, I used a for loop, and ,in the begging of the loop, I try to renovate the array values by using the const seq
.
But the sequence array keeps decreasing it's length as the for loop runs. I am trying to remove one item, do some stuff and put it back to the array so I can do the same thing with the next item.
const q = sequence;
for(let i= sequence.length-1; i>=0 ; i--){
sequence = q;
sequence.splice(i,1,);
console.log(sequence);
//do some other stuff here
}
output ex:
Input:sequence: [1, 3, 2]
Console Output:[ 1, 3 ]
[ 1 ]
[]
what i expected: [1, 3]
[1, 2]
[3,2]