DEV Community

Ranjith srt
Ranjith srt

Posted on

js - localstorage | sessionstorag

STORE DATA

//key value pair
localStorage.setItem("username1", "ElonMusk");

localStorage.setItem("username2", "JohnDoe");
Enter fullscreen mode Exit fullscreen mode

REDRIVE DATA


// keyname
// let usernameOne = localStorage.getItem("username1");

// console.log(usernameOne);

let usernameTwo = localStorage.getItem("username2");

console.log(usernameTwo);

Enter fullscreen mode Exit fullscreen mode

//! REMOVE DATA

localStorage.removeItem("username1");
Enter fullscreen mode Exit fullscreen mode

ALL DELETE

localStorage.clear();
Enter fullscreen mode Exit fullscreen mode

STORE DATA


// sessionStorage.setItem("Elon","Musk");
// sessionStorage.setItem("John","Doe");

sessionStorage.setItem("username1", "ElonMusk");

sessionStorage.setItem("username2", "JohnDoe");

Enter fullscreen mode Exit fullscreen mode

REDRIVE DATA


// keyname
let usernameOne = localStorage.getItem("username1");

console.log(usernameOne);

// let usernameTwo= localStorage.getItem("username2");

// console.log(usernameTwo);

Enter fullscreen mode Exit fullscreen mode

REMOVE DATA

sessionStorage.removeItem("username1");
Enter fullscreen mode Exit fullscreen mode

ALL DELETE

sessionStorage.clear();

Enter fullscreen mode Exit fullscreen mode

JSON


obj eppdi localStoragelaa store pannrathu.

let user = {
  id: 1,
  name: "Elon Musk",
  age: 50,
};

  STORE TO LOCAL STORAGR

//OBJ TO  ONVERT JSON
localStorage.setItem("user", JSON.stringify(user));

//REDRIVE PANNI PAAKA

//JSON stringify TO CONVERT obj

let Isuser = JSON.parse(localStorage.getItem("user")); // key

console.log(Isuser);


Enter fullscreen mode Exit fullscreen mode

Top comments (0)