remove objects from array javascript code example
Example 1: how to remove element from array in javascript
var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");
colors.splice(carIndex, 1);
Example 2: 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 3: js array delete specific element
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var filtered = array.filter(function(value, index, arr){
return value > 5;
});
Example 4: remove object in array javascript
someArray.shift();
someArray = someArray.slice(1);
someArray.splice(0, 1);
someArray.pop();
someArray = someArray.slice(0, a.length - 1);
someArray.length = someArray.length - 1;