Storage getItem() Method

Example

Get the value of the specified local storage item:

var x = localStorage.getItem("mytime");
Try it Yourself »

Description

The getItem() method returns value of the specified Storage Object item.

The getItem() method belongs to the Storage Object, which can be either a localStorage object or a sessionStorage object.


Browser Support

Method
getItem() 4 8 3.5 4 10.5

Syntax

localStorage.getItem(keyname)
Or:
sessionStorage.getItem(keyname)

Parameter Values

Parameter Description
keyname Required. A String specifying the name of the key you want to get the value of

Technical Details

DOM Version: Web Storage API
Return Value: A String, representing the value of the specified key

More Examples

Example

The same example, but using session storage instead of local storage.

Get the value of the specified session storage item:

var x = sessionStorage.getItem("test1");
Try it Yourself »

Example

You can also get the value by using dot notation (obj.key):

var x = sessionStorage.test1;
Try it Yourself »

Example

You can also get the value like this:

var x = sessionStorage["test1"];
Try it Yourself »

Related Pages

Web Storage Reference: setItem() Method

Web Storage Reference: removeItem() Method


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.