js arr filter remove item code example
Example 1: javascript remove from array by index
array.splice(index, 1);
Example 2: remove an element from array
var colors = ["red", "blue", "car","green"];
colors = colors.filter(data => data != "car");
colors = colors.filter(function(data) { return data != "car"});
Example 3: remove element from javascript array
const array = [2, 5, 9];
console.log(array);
const index = array.indexOf(5);
if (index > -1) {
array.splice(index, 1);
}
console.log(array);
Example 4: how to delete element in list javascript
let itemsToBeRemoved = ["Sunday", "Monday"]
var filteredArray = myArray.filter(item => !itemsToBeRemoved.includes(item))