Get started with localStorage CDN

MIT licensed

LocalStorage: library for storing/retrieving key-value pairs in browsers.

Tags:
  • localStorage

Stable version

Copied!

How to start using localStorage CDN


// Include the localStorage library from the CDN
const LocalStorage = require('https://cdn.cdnhub.io/localStorage/2.0.1/localStorage.min.js');

// Initialize localStorage
if (!window.localStorage) {
  window.localStorage = new LocalStorage();
}

// Set an item
window.localStorage.setItem('name', 'John Doe');

// Get an item
const name = window.localStorage.getItem('name');
console.log(name); // Output: John Doe

// Remove an item
window.localStorage.removeItem('name');

// Check if an item exists
const exists = window.localStorage.getItem('age') !== null;
console.log(exists); // Output: false
Copied!
Copied!
Copied!
Copied!
Copied!

All versions