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
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);
1var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
2newArr.splice(1,2)
3//remove 1 element from index 2
1// remove element at certain index without changing original
2let arr = [0,1,2,3,4,5]
3let newArr = [...arr]
4newArr.splice(1,1)//remove 1 element from index 1
5console.log(arr) // [0,1,2,3,4,5]
6console.log(newArr)// [0,2,3,4,5]
1const items = ['a', 'b', 'c', 'd', 'e', 'f']
2const i = 2
3const filteredItems = items.slice(0, i).concat(items.slice(i + 1, items.length))
4// ["a", "b", "d", "e", "f"]
5