I checked lots of documentation but couldnt find explanation for JSON.stringify([...mealIds,mealId]) . I understand we add mealId to the mealIds array . But can anybody send or share a link for this ? Another way to do this ?
function addMealToLocalStorage(mealId){
const mealIds = getMealsFromLocalStorage()
localStorage.setItem('mealIds',JSON.stringify([...mealIds,mealId]))
}
function removeMealFromLocalStorage(mealId){
const mealIds = getMealsFromLocalStorage();
localStorage.setItem('mealIds',JSON.stringify(mealIds.filter(x => x!== mealId)))
}
function getMealsFromLocalStorage(){
const mealIds = JSON.parse(localStorage.getItem('mealIds'))
return mealIds === null ? [] : mealIds
}