Skip to main content
Your favorite browser API in a modern version. localStorage provides persistent key-value storage that survives script reloads and restarts. Each script has its own isolated storage - scripts cannot access each other’s data. Unlike the browser version, values are serialized using the structured clone algorithm (same as IndexedDB), so any JS type is supported - not just strings.
Supported value types: objects, arrays, numbers, strings, booleans, null, Date, RegExp, Map, Set, ArrayBuffer, TypedArray. No more JSON.stringify / JSON.parse wrappers - just store and retrieve.

Overview

Methods

setItem, getItem, removeItem, clear, key, length.

Property access

Read and write values using direct property syntax.

Methods

localStorage.setItem


Stores a value under the given key. The value can be any type supported by the structured clone algorithm.
string
required
The key to store the value under.
any
required
The value to store. Any serializable type.

localStorage.getItem


Retrieves a value by key. Returns null if the key doesn’t exist.

localStorage.removeItem


Removes a key and its value from storage.

localStorage.clear


Removes all keys for this script. Other scripts’ storage is not affected.

localStorage.key


Returns the key name at the given index. Returns null if out of bounds.
number
required
Zero-based index into the key list.
key() and length scan storage internally - avoid calling them in hot loops or inside on("render", ...).

localStorage.length


Returns the number of stored keys.

Property access

You can also use direct property syntax via a Proxy - reads, writes, and deletes all work as expected.
Built-in property names (setItem, getItem, removeItem, clear, key, length) cannot be used as storage keys via property syntax. Use setItem / getItem for these names:

Recipes

Persistent settings

Kill counter across reloads

Per-player notes