use JSON in localstorage

localStorage only supports strings. Use JSON.stringify() and JSON.parse().

var names = [];
names[0] = prompt("New member name?");
localStorage.setItem("names", JSON.stringify(names));

var storedNames = JSON.parse(localStorage.getItem("names"));

Unexpected token o in JSON at position

=>Your data is already an object. No need to parse it. The javascript interpreter has already parsed it for you. or use trim

req.toAddr = JSON.parse(localStorage.getItem(“CURRENT_LOC”).trim());

This entry was posted in Angularjs. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s