Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

removing the first match in array

//removing the first match of 5 from [2,5,9,1,5,8,5])
function removeItemOnce(arr, value) {
  var index = arr.indexOf(value);
  if (index > -1) {
    arr.splice(index, 1);
  }
  return arr;
}

// Usage
console.log(removeItemOnce([2,5,9,1,5,8,5], 5))
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #removing #match #array
ADD COMMENT
Topic
Name
6+2 =