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