Am trying to implement a feature where an item is to be deleted from local storage when a user clicks a button. The item is part of an array stored in local storage. However am not able to
here is how the item is saved
const favBtns=meal.querySelectorAll(".fav-btn i")
const images = document.querySelectorAll('.meal-header > img')
favBtns.forEach((favBtn,i)=>{
favBtn.addEventListener("click", ()=>{
favBtn.classList.toggle("active")
console.log(images[i].src, images[i].alt)
myFavMeals.push({src: images[i].src, alt: images[i].alt})
localStorage.setItem("myFavMeals", JSON.stringify(myFavMeals))
showMeal
})
})
here is how am trying to delete the item
function clearfav(){
const clears=document.querySelectorAll("i#clear.fa.fa-window-close")
clears.forEach(clear=>{
clear.addEventListener("click",()=>{
let favmeals= JSON.parse(localStorage.getItem("myFavMeals"))
favmeals.forEach((favmeals,i)=>{
favmeals.splice(favmeals[i],1)
showMeal()
})
})
})
}