1var colors = ["red","blue","car","green"];
2var carIndex = colors.indexOf("car");//get "car" index
3//remove car from the colors array
4colors.splice(carIndex, 1); // colors = ["red","blue","green"]
1let value = 3
2
3let arr = [1, 2, 3, 4, 5, 3]
4
5arr = arr.filter(item => item !== value)
6
7console.log(arr)
8// [ 1, 2, 4, 5 ]
1const cars = ['farrari', 'Ice Cream'/* It is not an car */, 'tata', 'BMW']
2
3//to remove a specific element
4cars.splice(colors.indexOf('Ice Cream'), 1);
5
6//to remove the last element
7cars.pop();
1let forDeletion = [2, 3, 5]
2
3let arr = [1, 2, 3, 4, 5, 3]
4
5arr = arr.filter(item => !forDeletion.includes(item))
6// !!! Read below about array.includes(...) support !!!
7
8console.log(arr)
9// [ 1, 4 ]
1var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
2var filtered = array.filter(function(value, index, arr){
3 return value > 5;
4});
5//filtered => [6, 7, 8, 9]
6//array => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
1var array = ["Item", "Item", "Delete me!", "Item"]
2
3array.splice(2,1) // array is now ["Item","Item","Item"]