Created
September 1, 2022 15:11
-
-
Save syedjafer/2d7c872c1ad7eb279aa8417e39c5f5c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// setItem normal strings | |
window.sessionStorage.setItem("name", "goku"); | |
// getItem | |
const name = window.sessionStorage.getItem("name"); | |
console.log("name from localstorage, "+name); | |
// Storing an Object without JSON stringify | |
const data = { | |
"commodity":"apple", | |
"price":43 | |
}; | |
window.sessionStorage.setItem('commodity', data); | |
var result = window.sessionStorage.getItem('commodity'); | |
console.log("Retrived data without jsonified, "+ result); | |
// Storing an object after converting to JSON string. | |
var jsonifiedString = JSON.stringify(data); | |
window.sessionStorage.setItem('commodity', jsonifiedString); | |
var result = window.sessionStorage.getItem('commodity'); | |
console.log("Retrived data after jsonified, "+ result); | |
// remove item | |
window.sessionStorage.removeItem("commodity"); | |
var result = window.sessionStorage.getItem('commodity'); | |
console.log("Data after removing the key "+ result); | |
//length | |
console.log("length of local storage " + window.sessionStorage.length); | |
// clear | |
window.sessionStorage.clear(); | |
console.log("length of local storage - after clear " + window.sessionStorage.length); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment