Adding data to object stores

We can use  storeHandler to actually put data inside a table with the following code:

const open = window.indexedDB.open("types", 1);open.onupgradeneeded = () => {    const dbHandler = open.result;    const storeHandler = dbHandler.createObjectStore("frontend");    storeHandler.add({        latestVersion: 5,        cool: "yes",        easy2use: "yes"    }, "HTML5");};

Let's take a moment to understand what just happened. By calling storeHandler.add(), we were able to add data to our frontend table inside our types database (version 1). The first argument--that is, our passed object--is the value, which can be an object in indexedDB. Values can only be strings in localStorage. The second argument--that is, HTML5--is the name of our key.

The result ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.