Skip to content Skip to sidebar Skip to footer

Jq: Parse Localstorage & Stringify Values

I am storing some values in localStorage using stringify and I'm trying to parse them but it doesn't work for me. This is how I add the values: localStorage.setItem('a', JSON.strin

Solution 1:

That is because JSON.parse(localStorage.getItem('a')) returns an object. You cannot use an object like that as an argument in .text().

This works though:

$('p').text(JSON.parse(localStorage.getItem('a')).value);

Post a Comment for "Jq: Parse Localstorage & Stringify Values"