js remove object from array code example
Example 1: typescript remove object from array
const index = myArray.indexOf(key, 0);
if (index > -1) {
myArray.splice(index, 1);
}
Example 2: remove a particular element from array
var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");
colors.splice(carIndex, 1);
Example 3: javascript remove from array by index
array.splice(index, 1);
Example 4: 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 5: how to remove element from array in javascript
var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");
colors.splice(carIndex, 1);
Example 6: js remove object from array by value
let originalArray = [
{name: 'John', age: 23, color: 'red'},
{name: 'Ann', age: 21, color: 'blue'},
{name: 'Mike', age: 13, color: 'green'}
];
let filteredArray = originalArray.filter(value => value.age > 18);