When I add an item to the array it works but the splice does not.
JavaScript
x
9
1
const handleSportsFollowed = async (sport) => {
2
if (selectedSports.includes(sport)) {
3
selectedSports.splice(sport, 1);
4
alert("Removed");
5
} else {
6
selectedSports.push(sport);
7
}
8
}
9
Advertisement
Answer
You can remove elements that are equal to sport
from the array using:
JavaScript
1
2
1
selectedSports = selectedSports.filter(x => x != sport)
2