Skip to content

Instantly share code, notes, and snippets.

@taimursaeed
Created February 9, 2018 10:01
Show Gist options
  • Save taimursaeed/fabe4c9e746b8d6579a80b128c2543a9 to your computer and use it in GitHub Desktop.
Save taimursaeed/fabe4c9e746b8d6579a80b128c2543a9 to your computer and use it in GitHub Desktop.
Storing and Retrieving JSON from Local Storage
function storeItem(itemName, data) {
localStorage.setItem(itemName, btoa(JSON.stringify(data)));
}
function retrieveItem(itemName) {
var x = localStorage.getItem(itemName);
if (!x) { console.log("Element not found in local storage"); return false; }
localStorage.removeItem('x');
x = atob(x);
return $.parseJSON(x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment