QuickSnip LogoA light blue logo with a thunderbolt in bracketsQuickSnip

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.json

This 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