Storage
Persistent key-value storage backed by the host. The familiar web localStorage shape, reduced
to the three methods that matter. Values survive reloads.
At a glance
// save
localStorage.setItem('save', JSON.stringify({ level: 3, coins: 120 }))
// load (with a default)
const raw = localStorage.getItem('save')
const save = raw ? JSON.parse(raw) : { level: 1, coins: 0 }
// clear
localStorage.removeItem('save')API
localStorage.getItem(key: string): string | null // null if the key was never set
localStorage.setItem(key: string, value: string) // store / overwrite
localStorage.removeItem(key: string) // deleteThat is the whole surface — no clear(), no length, no key(i) iteration.
Note
values are strings only. JSON.stringify / JSON.parse anything structured.
See also
- Networking —
fetchif state should live on a server instead