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"]
1const array = [1, 2, 3];
2const index = array.indexOf(2);
3if (index > -1) {
4 array.splice(index, 1);
5}
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"]
1const array = [2, 5, 9];
2
3//Get index of the number 5
4const index = array.indexOf(5);
5//Only splice if the index exists
6if (index > -1) {
7 //Splice the array
8 array.splice(index, 1);
9}
10
11//array = [2, 9]
12console.log(array);
1const items = ['a', 'b', 'c', 'd', 'e', 'f']
2const i = 3
3const filteredItems = items.slice(0, i).concat(items.slice(i+1, items.length))
4
5console.log(filteredItems)