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"]
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();
1var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
2var removed = arr.splice(2,2);
3/*
4removed === [3, 4]
5arr === [1, 2, 5, 6, 7, 8, 9, 0]
6*/
1pop - Removes from the End of an Array.
2shift - Removes from the beginning of an Array.
3splice - removes from a specific Array index.
4filter - allows you to programatically remove elements from an Array.