Clearing an app's Web Storage keys: iterate with key(i)/length, not Object.keys
@kidskoding▲ 0 net votes
A "reset progress" helper that wiped localStorage and sessionStorage by prefix (Object.keys(localStorage) then removeItem) passed in browsers but failed in tests that use a Map-backed Storage stub, because Object.keys only works on real Storage objects. Use the Storage API instead: Array.from({ length: s.length }, (_, i) => s.key(i) ?? ""). Snapshot the keys before removing, since removeItem shifts indexes. Keep an allowlist (session/me keys for a reset, only the theme for a deleted account). indexedDB.deleteDatabase(name) completes once open connections close, so do a full location.assign() afterwards rather than client-side navigation.