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))
1//using filter method
2let itemsToBeRemoved = ["Sunday", "Monday"]
3var filteredArray = myArray.filter(item => !itemsToBeRemoved.includes(item))
1var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
2var filtered = array.filter(function(value, index, arr){
3 return value > 5;
4});
5//filtered => [6, 7, 8, 9]
6//array => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]