Example 1: remove a particular element from array
var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");
colors.splice(carIndex, 1);
Example 2: remove item from array javascript
const array = [2, 5, 9];
console.log(array);
const index = array.indexOf(5);
if (index > -1) {
array.splice(index, 1);
}
console.log(array);
Example 3: js remove item array
let originalArray = [1, 2, 3, 4, 5];
let filteredArray = originalArray.filter((value, index) => index !== 2);
Example 4: how to remove item from array javascript
var array = ["Item", "Item", "Delete me!", "Item"]
array.splice(2,1)
Example 5: remove item from array javascript
let someArray = [
{name:"Kristian", lines:"2,5,10"},
{name:"John", lines:"1,19,26,96"},
{name:"Kristian", lines:"2,58,160"},
{name:"Felix", lines:"1,19,26,96"}
];
someArray = someArray.filter(person => person.name != 'John');
It will remove John!
Example 6: remove element from array javascript
data = [1, 2, 3, 4, 5, 6];
let filteredData = data.filter((i) => {
return i > 2
});
console.log(filteredData)