0

I want to remove an element based on its position; not by it's value. I'm using filter method to delete an element from array. But the problem is, when there are multiple items of same name it filters all of them. I need my code to remove only one element at once based on its position or index number but it is clearing items based on it's value.

var aid = 0;
    arr = ["hello", "hey", "hello", "hi"]; 

arr = arr.filter(function(item) {
  return item !== newarr[aid]; 
});
  • Expected output: ["hello", "hey", "hi"]
  • Actual output: ["hey", "hi"]

Please help me. I'm stuck very badly with this program. I have also tried slice method but its not working correctly.

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132

0 Answers0