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: "[email protected]" });
request.onsuccess = function(event) {
alert("Amit has been added to your database.");
};
request.onerror = function(event) {
alert("Unable to add data\r\nAmit is already exist in your database! ");
}
}Above, we added the following details in the database:
const employeeData = [
{ id: "001", name: "Amit", age: 28, email: "[email protected]" },
];