0

The code I have right now, removes most of the instances, however it does not remove all of them. What am I doing wrong?

let nums = [1, 90, 90, 1123, 90, 4534, 90, 90, 90, 90, 90];

function removeAll(array, item) {
  for (var i = 0; i < array.length; i++) {
    if (array[i] === item) {
      array.splice(array.indexOf(item), 1);
    }
  }
  return array;
}
    
console.log(removeAll(nums, 90));
str
  • 42,689
  • 17
  • 109
  • 127
Trickster
  • 57
  • 4

1 Answers1

0

let nums = [1, 90, 90, 1123, 90, 4534, 90, 90, 90, 90, 90];

function removeAll(array, item) {
  return array.filter(function(value) {
    return value !== item;
  });
}

console.log(removeAll(nums, 90));
Sivakumar Tadisetti
  • 4,865
  • 7
  • 34
  • 56