Google News
logo
JavaScript IndexedDB - Interview Questions
How do we delete an IndexedDB database using JavaScript?
There are two ways to delete an IndexedDB database. The manual approach is to delete the database in the application manifest pane. The programmatic approach using JavaScript requires us to use the deleteDatabase method.

The deleteDatabase() method of the IDBFactory interface requests the deletion of a database. The method returns an IDBOpenDBRequest object immediately and performs the deletion operation asynchronously.

If the database successfully deletes, a success event fires on the request object returned from this method, resulting in undefined. If an error occurs while the database deletes, an error event fires on the request object returned from this method.

Code Example :
let deleteRequest = indexedDB.deleteDatabase("myDatabase");

deleteRequest.onsuccess = function() {
  console.log("Database deleted successfully");
};

deleteRequest.onerror = function(event) {
  console.error("Error deleting database:", event.target.errorCode);
};?
Advertisement