remove item from array javascript

JavaScript
// Remove single item
function removeItemOnce(arr, value) {
   var index = arr.indexOf(value);
   if (index > -1) {
      arr.splice(index, 1);
   }
   return arr;
}

// Remove all items
function removeItemAll(arr, value) {
   var i = 0;
   while (i < arr.length) {
      if (arr[i] === value) {
         arr.splice(i, 1);
      } else {
         ++i;
      }
   }
   return arr;
}

// Usage
console.log(removeItemOnce([2, 5, 9, 1, 5, 8, 5], 5));
console.log(removeItemAll([2, 5, 9, 1, 5, 8, 5], 5));var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");//get  "car" index
//remove car from the colors array
colors.splice(carIndex, 1); // colors = ["red","blue","green"]var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift();var list = ["bar", "baz", "foo", "qux"];
list.shift()//["baz", "foo", "qux"]const array = [2, 5, 9];

console.log(array);

const index = array.indexOf(5);
if (index > -1) {
  array.splice(index, 1);
}

// array = [2, 9]
console.log(array); let someArray = [
               {name:"Kristian", lines:"2,5,10"},
               {name:"John", lines:"1,19,26,96"},
               {name:"Kristian", lines:"2,58,160"},
               {name:"Felix", lines:"1,19,26,96"}
            ];

someArray = someArray.filter(person => person.name != 'John');
It will remove John!
Source

Also in JavaScript: