Search.../

getItem( )

Gets an item from local, session, or memory storage.

Description

If an item does not exist, getItem() resolves to null.

Syntax

function getItem(key: string): string

getItem Parameters

NAME
TYPE
DESCRIPTION
key
string

The key of the item to get.

Returns

The retrieved item value.

Return Type:

string

Related Content:

Was this helpful?

Retrieve an item from local storage

Copy Code
1import {local} from 'wix-storage-frontend';
2
3// ...
4
5let value = local.getItem("key"); // "value"
Retrieve an item from session storage

Copy Code
1import {session} from 'wix-storage-frontend';
2
3// ...
4
5let value = session.getItem("key"); // "value"
Retrieve an item from memory storage

Copy Code
1import {memory} from 'wix-storage-frontend';
2
3// ...
4
5let value = memory.getItem("key"); // "value"
Manage data stored in the browser

This example shows how to manage data stored in the browser. Adjust the import statement to use different storage types. You can test out the code in our example template.

Copy Code
1import {local as storage} from 'wix-storage-frontend';
2// Alternatively use:
3// import {session as storage} from 'wix-storage-frontend';
4// import {memory as storage} from 'wix-storage-frontend';
5
6$w.onReady(async function () {
7 $w('#setItemButton').onClick( () => {
8 storage.setItem($w('#setKey').value, $w('#setValue').value);
9 $w('#setKey').value = undefined;
10 $w('#setValue').value = undefined;
11 });
12
13 $w('#getItemButton').onClick( () => {
14 $w('#getValue').value = storage.getItem($w('#getKey').value);
15 $w('#getKey').value = undefined;
16 });
17
18 $w('#removeItemButton').onClick( () => {
19 storage.removeItem($w('#removeKey').value);
20 $w('#removeKey').value = undefined;
21 });
22
23 $w('#clearButton').onClick( () => {
24 storage.clear();
25 });
26});
27