I have spent a whole day on this, googling and searching for answers but still could not figure out.
My code is a bit long and it works well in Firefox but gets \"U
At some point, something you did corrupted the value of your LocalStorage for that key. LocalStorage can only store strings, so if you pass anything else to it, it will convert it to a string. Since your value is 'undefined'
, that means that at some point, you probably did something like this on accident:
var value;
localStorage.setItem('key', value);
In this case, value
is undefined
, which is not a string. When this gets saved, it will be converted however. Unfortunately, "undefined"
is not valid JSON. That means that when it tries to parse, it will throw an exception.
To fix your issue, you should clear the bad value out with removeItem
.
localStorage.removeItem("customerDatabase");