localStorage.setItem() Store data
Last updated: 2026-09-09
localStorage.setItem() Store data
setItem stores a key-value pair in localStorage. Values must be strings — use JSON.stringify for objects.
| Category | Browser (BOM) |
|---|---|
| ES version | DOM |
📝 Syntax
localStorage.setItem('key', 'value');
⚙️ Parameters
| key | The storage key. |
|---|---|
| value | The value to store (string). |
Returns:undefined.
Mutates the original:Yes (in place)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
Zhang
💡 Tip JSON.stringify before storing objects; JSON.parse when reading.
⚠️ Warning localStorage has ~5MB limit — throws QuotaExceededError when exceeded.
🌐 Browser support
| Browser | |||||
|---|---|---|---|---|---|
| localStorage.setItem() | ✓ v1 | ✓ v12 | ✓ v1 | ✓ v1 | ✓ v1 |
| Supported by all modern browsers | |||||
🏷️ Related Items
💡 Related Cases
More case studies coming soon — check back later.
📚 Related Tutorials
❓ FAQ
Qt
Ar
Qt
Ar
Qs
An