HTML5 IndexedDB Example


The following function is an example of IndexedDB to add data:

function add() {
   var request = db.transaction(["employee"], "readwrite")
   .objectStore("employee")
   .add({ id: "001", name: "Amit", age: 28, email: "demo1@example.com" });
   request.onsuccess = function(event) {
      alert("Amit has been added to your database.");
   };
   request.onerror = function(event) {
      alert("Unable to add data\r
Amit is already exist in your database! ");    } }

Above, we added the following details in the database:

const employeeData = [
   { id: "001", name: "Amit", age: 28, email: "demo1@example.com" },
];

Updated on: 29-Jan-2020

156 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements