How to access local storage??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to access local storage???

I wanted to make an for which I wanted to save some user data but there is no lesson in Sololearn which teaches how to access local storage I JavaScript. Can someone please help me ? I want some websites for reference. Any sample example will also do.

9th Jan 2024, 3:40 PM
Web Developer AD
5 Answers
+ 7
To store localStorage.setItem(key, value); To access: localStorage.getItem(key); To remove: localStorage.remove(key)
9th Jan 2024, 4:11 PM
A͢J
A͢J - avatar
+ 3
Also, to clear all: localStorage.clear();
9th Jan 2024, 4:31 PM
🇮🇱 Radin Masiha 🇮🇱
🇮🇱 Radin Masiha 🇮🇱 - avatar
+ 3
Arjun Dawande As you want to store users data in localStorage so here value will be users data and key will be each unique user for example. There are 2 users Arjun and AJ so data will be store like: localStorage.setItem('arjun', '1233') localStorage.setItem('aj', '1233') So now you can access each users data by using key 'arjun' or 'aj' Remember value can be same but keys should be uniques.
10th Jan 2024, 2:34 AM
A͢J
A͢J - avatar
+ 3
Thanks A͢J . I now understood it very well. 🙂
10th Jan 2024, 12:24 PM
Web Developer AD
+ 2
Thank you A͢J & 🇮🇱 Radin Masiha 🇮🇱 for your answer but still I am not understanding what you meant by "key" and "value". Will you please explain me?
10th Jan 2024, 12:51 AM
Web Developer AD