Excluir item da lista JavaScript
const array = [1, 2, 3];
const index = array.indexOf(2);
if (index > -1) {
array.splice(index, 1);
}
TheProgrammer
const array = [1, 2, 3];
const index = array.indexOf(2);
if (index > -1) {
array.splice(index, 1);
}
var myArray = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
//removing element using splice method --
//arr.splice(index of the item to be removed, number of elements to be removed)
//Here lets remove Sunday -- index 0 and Monday -- index 1
myArray.splice(0,2)
//using filter method
let itemToBeRemoved = ["Sunday", "Monday"]
var filteredArray = myArray.filter(item => !itemToBeRemoved.includes(item))
//using filter method
let itemsToBeRemoved = ["Sunday", "Monday"]
var filteredArray = myArray.filter(item => !itemsToBeRemoved.includes(item))
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var filtered = array.filter(function(value, index, arr){
return value > 5;
});
//filtered => [6, 7, 8, 9]
//array => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]