re: Saving Data in JavaScript Without a Database VIEW POST


Another way is (or will be) kv storage. It's the first built in module for the web.

below code copied from article:

import {storage} from 'std:kv-storage';

const main = async () => {
  const oldPreferences = await storage.get('preferences');

  document.querySelector('form').addEventListener('submit', async () => {
    const newPreferences = Object.assign({}, oldPreferences, {
      // Updated preferences go here...

    await storage.set('preferences', newPreferences);

It uses indexedDb under the hood, but provides a convenient API similar to localStorage. With the main difference that it is asynchronous and therefore doesn't block the main thread.

code of conduct - report abuse