remove element from array at index javascript code example
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: javascript remove from array by index
array.splice(index, 1);
Example 3: 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 4: how to remove element from array in javascript
var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");
colors.splice(carIndex, 1);
Example 5: array remove index from array
const array = [2, 5, 9];
const index = array.indexOf(5);
if (index > -1) {
array.splice(index, 1);
}
console.log(array);
Example 6: js remove element from array
let arrDeletedItems = array.splice(start[, deleteCount[, item1[, item2[, ...]]]])