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
string
required
The key to store the value under.
any
required
The value to store. Any serializable type.
localStorage.getItem
null if the key doesn’t exist.
localStorage.removeItem
localStorage.clear
localStorage.key
null if out of bounds.
number
required
Zero-based index into the key list.
localStorage.length
Property access
You can also use direct property syntax via aProxy - reads, writes, and deletes all work as expected.