LeCodesdocs

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

TypeScript
// 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

TypeScript
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)               // delete

That 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

  • Networkingfetch if state should live on a server instead