remove array element in 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"]let value = 3

let arr = [1, 2, 3, 4, 5, 3]

arr = arr.filter(item => item !== value)

console.log(arr)
// [ 1, 2, 4, 5 ]var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var filtered = array.filter(function(value, index, arr){
    return value > 5;
});
//filtered => [6, 7, 8, 9]
//array => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]// remove element at certain index without changing original
let arr = [0,1,2,3,4,5]
let newArr = [...arr]
newArr.splice(1,1)//remove 1 element from index 1
console.log(arr) // [0,1,2,3,4,5]
console.log(newArr)// [0,2,3,4,5]//you can use two functions depending of what you want to do:

let animals1 = ["dog", "cat", "mouse"]
delete animals1[1]
/*this deletes all the information inside "cat" but the element still exists
so now you'll have this:*/
console.log(animals1)//animals1 = ["dog", undefined, "mouse"]

//if you want to delete it completely, you have to use array.splice:

let animals2 = ["dog", "cat", "mouse"]
animals2.splice(1, 1)
/*the first number means the position from which you want to start to delete
and the second is how much elements will be deleted*/
console.log(animals2)//animals2 = ["dog", "mouse"]
/*Now you don't have undefined
If you did this:*/
let animals3 = ["dog", "cat", "mouse"]
animals3.splice(0, 2)//you'll have this:
console.log(animals3)//animals 3 = "mouse"
/*This happens because I put a 2 in the second parameter so it deleted
two elements from position 0
Try copying this code in your console and whatch*/
Source

Also in JavaScript: