I want to remove the negative elements of the copied array by pop() method but it removes only the last element of the array. Anyone knows where's the problem? The code is in the image
I tried:
const scores = [128, 0, -8, 50, 2, 3];
const betterScores = Array.from(scores);
for (const s of betterScores) {
if (s < 0) {
betterScores.pop(s);
}
}
console.log(betterScores);
I wanted to have betterScores = [128,50,2,3]
but I got [128,0,-8,50,2]
.