This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Note: This feature is available in Web Workers.
The createObjectStore() method of the IDBDatabase interface creates and returns a new IDBObjectStore.
The method takes the name of the store as well as a parameter object that lets you define important optional properties. You can use the property to uniquely identify individual objects in the store. As the property is an identifier, it should be unique to every object, and every object should have that property.
This method can be called only within a versionchange transaction.
createObjectStore(name) createObjectStore(name, options)
nameThe name of the new object store to be created. Note that it is possible to create an object store with an empty name.
options OptionalAn options object whose attributes are optional parameters to the method. It includes the following properties:
keyPath OptionalThe key path to be used by the new object store. If empty or not specified, the object store is created without a key path and uses out-of-line keys. You can also pass in an array as a keyPath.
autoIncrement OptionalIf true, the object store has a key generator. Defaults to false.
A new IDBObjectStore.
This method may raise a DOMException with a name of one of the following types:
ConstraintError DOMException
Thrown if an object store with the given name (based on a case-sensitive comparison) already exists in the connected database.
InvalidAccessError DOMException
Thrown if autoIncrement is set to true and keyPath is either an empty string or an array.
InvalidStateError DOMException
Thrown if the method was not called from a versionchange transaction callback.
SyntaxErrorThrown if the keyPath option contains an invalid key path.
TransactionInactiveError DOMException
Thrown if a request is made on a source database that does not exist (for example, when the database has been deleted or removed), or if the associated upgrade transaction has completed or is processing a request.
// Let us open our database
const request = window.indexedDB.open("toDoList", 4);
// This handler is called when a new version of the database
// is created, either when one has not been created before
// or when a new version number is submitted by calling
// window.indexedDB.open().
// This handler is only supported in recent browsers.
request.onupgradeneeded = (event) => {
const db = event.target.result;
db.onerror = (event) => {
note.appendChild(document.createElement("li")).textContent =
"Error loading database.";
};
// Create an objectStore for this database
const objectStore = db.createObjectStore("toDoList", {
keyPath: "taskTitle",
});
// define what data items the objectStore will contain
objectStore.createIndex("hours", "hours", { unique: false });
objectStore.createIndex("minutes", "minutes", { unique: false });
objectStore.createIndex("day", "day", { unique: false });
objectStore.createIndex("month", "month", { unique: false });
objectStore.createIndex("year", "year", { unique: false });
objectStore.createIndex("notified", "notified", { unique: false });
note.appendChild(document.createElement("li")).textContent =
"Object store created.";
};
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
createObjectStore |
23 | 12 | 10 | 15 | 8 | 25 | 22 | 14 | 8 | 1.5 | 4.4 | 8 |
IDBDatabase
IDBTransaction
IDBKeyRange
IDBObjectStore
IDBCursor
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/createObjectStore