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))
1// example (remove middle element(s) in the array)
2let yourArray = ["aaa", "bbb", "ccc", "ddd"];
3yourArray.splice(2,1); // yourArray = ["aaa", "bbb", "ddd"]
4
5// syntax:
6// <array-name>.splice(<start-index>,<number-of-elements-to-remove>);
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);
1var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
2newArr.splice(1,2)
3//remove 1 element from index 2