Search...
setItem( )
Stores an item in local, session, or memory storage.
Note: You can store up to 50kb of data in local and session storage and up to 1mb in memory storage.
Syntax
function setItem(key: string, value: string | number | Array<string>): void
setItem Parameters
NAME
TYPE
DESCRIPTION
key
string
The key of item to set.
value
string | number | Array<string>
The value of the item to set.
Returns
This function does not return anything.
Return Type:
void
Related Content:
Was this helpful?
Store an item in local storage
Copy Code
1import {local} from 'wix-storage-frontend';23// ...45local.setItem("key", "value");
Store an item in session storage
Copy Code
1import {session} from 'wix-storage-frontend';23// ...45session.setItem("key", "value");
Store an item in memory storage
Copy Code
1import {memory} from 'wix-storage-frontend';23// ...45memory.setItem("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';56$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 });1213 $w('#getItemButton').onClick( () => {14 $w('#getValue').value = storage.getItem($w('#getKey').value);15 $w('#getKey').value = undefined;16 });1718 $w('#removeItemButton').onClick( () => {19 storage.removeItem($w('#removeKey').value);20 $w('#removeKey').value = undefined;21 });2223 $w('#clearButton').onClick( () => {24 storage.clear();25 });26});27