Cleared localStorage in the browser Dev Tools as they were holding incorrect information from previous updates. My code above was fine.
'Uncaught Syntax Error: Unexpected token o'
-
18-06-2023 - |
Question
var currentFood = JSON.parse(localStorage.getItem("currentFood"));
<some HTML using the currentFood object>
$('#addFood').on("click", function(){
var allFood = JSON.parse(localStorage.getItem("allFood")) || [];
allFood.push(currentFood);
localStorage.setItem("allFood", JSON.stringify(allFood));
});
After checking console.log, currentFood is returning the correct object, however, the following code is returning an "unexpected token error 0" on the first line of my click event.
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow