Answers for "localstorage utility javascript"

2

localStorage in javascript

// 'key' could be any variable to address your 'value'. 
//'value' could be of any data-type.

// Save data to localStorage
localStorage.setItem('key', JSON.stringify('value'));

// Get saved data from localStorage
localStorage.getItem('key') ? JSON.parse(localStorage.getItem('key') : '';

// Remove saved data from localStorage
localStorage.removeItem('key');

// Remove all saved data from localStorage
localStorage.clear();
Posted by: Guest on October-09-2021
5

javascript localstorage

localStorage.setItem("user_name", "Bob");

document.body.addEventListener("click", function(){
  alert(localStorage.getItem("user_name"))
});
Posted by: Guest on May-14-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language