Skip to content
Related Articles

Related Articles

HTML | DOM Storage getItem() Method

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 26 Jul, 2019

The getItem() method is used to retrieve the storage object which is specified by the user. This storage object can be localStorage object or sessionStorage object.


    For local storage:


    For session storage:


Parameters: It requires Keyname which specifies name of the key used for getting the value.

Return Value: A String, representing the value of the specified key.

Example: Get item from local storage.

<!DOCTYPE html>
    <!--script for creating new local 
      storage item and retrieve it -->
        function createItem() {
   = "GeeksforGeeks";
        function myFunction() {
            // get name of item from local storage.
            var x = localStorage.getItem("name");
            document.getElementById("demo").innerHTML =
    <h1>Welcome to GeeksforGeeks</h1>
    <h3>The Storage getItem() Method</h3>
      Click on button to create a 
      local storage item 
    <button onclick="createItem()">
      Create local storage item
      Click the button to get the item value:
    <button onclick="myFunction()">
      Get the item value
    <p id="demo"></p>



Supported Browsers: The browser supported by DOM getItem() Method are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!