delete element from array js by index 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: locate and delete an object in an array
var apps = [{id:34,name:'My App',another:'thing'},{id:37,name:'My New App',another:'things'}];
var removeIndex = apps.map(function(item) { return item.id; }).indexOf(37);
apps.splice(removeIndex, 1);
Example 3: delete item from list javascript
const array = [1, 2, 3];
const index = array.indexOf(2);
if (index > -1) {
array.splice(index, 1);
}
Example 4: remove array elements javascript
let forDeletion = [2, 3, 5]
let arr = [1, 2, 3, 4, 5, 3]
arr = arr.filter(item => !forDeletion.includes(item))
console.log(arr)
Example 5: remove a value to an array of javascript
var data = [1, 2, 3];
data.splice(1, 1);
data.pop();