Remove Item from Array in ES6

In ES6, you can remove specific elements from an array using the filter method, as shown below:

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

arr = arr.filter(item => item !== elementToDelete);

console.log(arr); // Output: [1, 2, 4, 5]

In the code above, we first define an array arr, then use the filter method to remove elements in the array that are not equal to the specified element elementToDelete, and finally assign the new array back to the original array arr.

bannerAds