📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
🎓 Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
Tip - Coding in Browser
- Enter some domain in the web browser, for example - "https://www.javaguides.net/".
- Inspect web page and go to console.
- Type below JavaScript code snippet and hit enter button.
localStorage.setItem("firstName", "Ramesh");
- Go to Application tab under Storage menu you can find LocalStorage and domain "https://www.javaguides.net/".
- Click on domain "https://www.javaguides.net/" and filter for "key1".
JavaScript LocalStorage Methods
- setItem(): Add key and value to LocalStorage
- getItem(): Retrieve a value by the key from LocalStorage
- removeItem(): Remove an item by key from LocalStorage
- clear(): Clear all LocalStorage
- key(): Passed a number to retrieve nth key of a LocalStorage
Syntax
window.localStorage
localStorage.setItem("key", "value");
var lastname = localStorage.getItem("key");
localStorage.removeItem("key");
localStorage.clear();
var KeyName = localStorage.key(index);
localStorage.setItem() Method
localStorage.setItem("firstName", "Ramesh");
var user = {
firstName : "Ramesh",
lastName : "Fadatare"
}
localStorage.setItem("id", JSON.stringify(user));
localStorage.getItem() Method
localStorage.getItem('id');
"{"firstName":"Ramesh","lastName":"Fadatare"}"
JSON.parse(localStorage.getItem('id'));
localStorage.removeItem() Method
localStorage.removeItem('id');
localStorage.clear() Method
localStorage.clear();
localStorage.key() Method
var KeyName = localStorage.key(index);
Comments
Post a Comment
Leave Comment