Check if Item Exists in localStorage
Checks if a specific item exists in localStorage.
- localstorage
- storage
Install
npx shadcn@latest add https://quicksnip.dev/r/check-if-item-exists-in-localstorage.jsonThis snippet is not verified yet. Review it before use, or help verify it.
Code
const isItemInLocalStorage = (key) => {
return localStorage.getItem(key) !== null;
};Usage
console.log(isItemInLocalStorage('user')); // Output: true or false