To add data to a data store in IndexedDB, we need to follow these steps:

  1. Open a database.

  2. Create an object store.

  3. Start a transaction.

  4. Add the data to the object store using the add() method.

Till now, we know how to open a database and create an object store. Let’s see how to start a transaction and add data to the object store.

Start a transaction

To add data to a database, we need to create transactions. A transaction is a unit of work that makes changes to the database. To create a transaction, we should use the syntax below:

Get hands-on with 1200+ tech skills courses.