How Can I Remove a Specific Item from an Array in JavaScript

From WikiOD

Method 1:[edit | edit source]

Find the index of the element and remove it using splice

const array = ["a", "b", "c"];

console.log(array);
// ["a", "b", "c"]

const index = array.indexOf("b");

if (index > -1) {
  array.splice(index, 1);
}

console.log(array); 
// ["a", "c"]

Method 2:[edit | edit source]

If you have no idea about value, Find the value element using forEach

const array = [2, 4, 5, 8];

console.log(array)
// [2,4,5,8]

array.forEach((val,index) => {
  if (val % 2 != 0){
    array.splice(index, 1);
  }
})

console.log(array)
// [2,4,8]