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 myArray = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
2
3//removing element using splice method --
4//arr.splice(index of the item to be removed, number of elements to be removed)
5//Here lets remove Sunday -- index 0 and Monday -- index 1
6 myArray.splice(0,2)
7
8//using filter method
9let itemToBeRemoved = ["Sunday", "Monday"]
10var filteredArray = myArray.filter(item => !itemToBeRemoved.includes(item))
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);
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 ]
1//using filter method
2let itemsToBeRemoved = ["Sunday", "Monday"]
3var filteredArray = myArray.filter(item => !itemsToBeRemoved.includes(item))