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: js remove from array by value
const index = array.indexOf(item);
if (index !== -1) array.splice(index, 1);
Example 3: how to delete an element from an array
var array = [123, "yee", true];
array.pop(index);
Example 4: js remove element from 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 5: remove item at index in array javascript
let arr = [0,1,2,3,4,5]
let newArr = [...arr]
newArr.splice(1,1)
console.log(arr)
console.log(newArr)
Example 6: 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!