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 one element from array
const array = [2, 5, 9];
console.log(array);
const index = array.indexOf(5);
if (index > -1) {
array.splice(index, 1);
}
console.log(array);
Example 3: remove array js
var ar = [1, 2, 3, 4, 5, 6];ar.length = 4;
var ar = [1, 2, 3, 4, 5, 6];ar.pop();
var ar = ['zero', 'one', 'two', 'three'];ar.shift();
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];var removed = arr.splice(2,2);
["bar", "baz", "foo", "qux"]list.splice(0, 2)
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
for( var i = 0; i < arr.length; i++){
if ( arr[i] === 5) {
arr.splice(i, 1);
}
}
var arr = [1, 2, 3, 4, 5, 5, 6, 7, 8, 5, 9, 0];
for( var i = 0; i < arr.length; i++){
if ( arr[i] === 5) {
arr.splice(i, 1); i--;
}
}
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var filtered = array.filter(function(value, index, arr){
return value > 5;
});
var evens = _.remove(array, function(n) {
return n % 2 === 0;
});
console.log(array);
function arrayRemove(arr, value) {
return arr.filter(function(ele){
return ele != value; });
}
var result = arrayRemove(array, 6);
var ar = [1, 2, 3, 4, 5, 6];delete ar[4];