LocalStorage.getItem JavaScript Example

LocalStorage.getItem() Method: Retrieve a value by the key from LocalStorage.


The syntax for SAVING data to localStorage:
localStorage.setItem("key", "value");
The syntax for READING data from localStorage:
var lastname = localStorage.getItem("key");

localStorage.getItem() Method Example

Check out LocalStorage.setItem JavaScript Example to add key and value to LocalStorage.

The getItem() method allows you to access the data stored in the browser’s localStorage object.
It accepts only one parameter which is the key and returns the value as a string.
To retrieve the user object from the key stored above:
This returns a string with value as;
To use this value, you would have to convert it back to an object using JSON.parse() method.

Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course