remove array element 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: how to remove element from array in javascript
var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");
colors.splice(carIndex, 1);
Example 3: how to remove element from array in javascript
let numbers = [1, 2, 3, 4, 5];
numbers.pop();
numbers.shift();
let threeIndex = numbers.indexOf(3);
numbers.splice(threeIndex, 1);
numbers.splice(threeIndex, 1, 7)
Example 4: remove an element from array
var colors = ["red", "blue", "car","green"];
colors = colors.filter(data => data != "car");
colors = colors.filter(function(data) { return data != "car"});
Example 5: how to delete an element from an array
var array = [123, "yee", true];
array.pop(index);
Example 6: js array delete specific element
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var removed = arr.splice(2,2);