You need to find the index for splice. Check Document how splice work
const handleSportsFollowed = async (sport) => {
if (selectedSports.includes(sport)) {
selectedSports.splice(selectedSports.indexOf(sport), 1);
console.log("if selectedSports ", selectedSports);
} else {
selectedSports.push(sport);
console.log("else selectedSports", selectedSports);
}
Working example
const selectedSports = ['Jan', 'March', 'April', 'June'];
const testFun = (sport) => {
if (selectedSports.includes(sport)) {
selectedSports.splice(selectedSports.indexOf(sport), 1);
console.log("selectedSports ", selectedSports);
} else {
selectedSports.push(sport);
console.log("selectedSports", selectedSports);
}
}
testFun("March");
splicemethod. You can have a look here MDN documentation.