Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

removes all item occurrences in array

//removes all 5 occurrences in array [2,5,9,1,5,8,5]
function removeItemAll(arr, value) {
  var i = 0;
  while (i < arr.length) {
    if (arr[i] === value) {
      arr.splice(i, 1);
    } else {
      ++i;
    }
  }
  return arr;
}
console.log(removeItemAll([2,5,9,1,5,8,5], 5))
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #removes #item #occurrences #array
ADD COMMENT
Topic
Name
1+2 =