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.

Était-ce utile?

La solution

Cleared localStorage in the browser Dev Tools as they were holding incorrect information from previous updates. My code above was fine.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top