Removing and adding item / element in a array is very common thing by a JavaScript developer. Here we have the Fastest Way to Remove a Specific Item from an Array.

Below the JavaScript Program to Remove Specific Item From an Array.

Example: we have an array [25, 51, 19] and I want to remove the 25 from it, using the indexOf and splice it can be done easily.

const arr = [1, 25, 51, 19];

console.log(arr);

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

// arr= [1, 51, 19]
console.log(arr); 

Using ES6

var value = 25;

var arr = [1, 25, 51, 19]

arr = arr.filter(function(item) {
    return item !== value
})

console.log(arr)
// [1, 51, 19]

Similar Posts