Answers for "how to store data in localstorage"

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
0

store data to the browser’s localStorage

export const setToLS = (key, value) => {
  window.localStorage.setItem(key, JSON.stringify(value));
}

export const getFromLS = key => {
  const value = window.localStorage.getItem(key);

  if (value) {
    return JSON.parse(value);
  }
}
Posted by: Guest on June-25-2021
0

localstorage

localStorage.removeItem('myCat');
Posted by: Guest on August-09-2020

Code answers related to "how to store data in localstorage"

Code answers related to "Javascript"

Browse Popular Code Answers by Language