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 data = [1, 2, 3];
2
3// remove a specific value
4// splice(starting index, how many values to remove);
5data = data.splice(1, 1);
6// data = [1, 3];
7
8// remove last element
9data = data.pop();
10// data = [1, 2];
1const array = [2, 5, 9];
2
3console.log(array);
4
5const index = array.indexOf(5);
6if (index > -1) {
7 array.splice(index, 1);
8}
9
10// array = [2, 9]
11console.log(array);
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 ]
1const array = [2, 5, 9];
2
3console.log(array);
4
5const index = array.indexOf(5);
6if (index > -1) {
7 array.splice(index, 1);
8}
9// array = [2, 9]
10console.log(array);