IDBObjectStore: createIndex() method
Baseline
Widely available
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 createIndex() method of the
IDBObjectStore interface creates and returns a new
IDBIndex object in the connected database. It creates a new
field/column defining a new data point for each database record to contain.
Bear in mind that IndexedDB indexes can contain any JavaScript data type; IndexedDB uses the structured clone algorithm to serialize stored objects, which allows for storage of simple and complex objects.
Note that this method must be called only from a VersionChange transaction
mode callback.
Syntax
createIndex(indexName, keyPath)
createIndex(indexName, keyPath, options)
Parameters
indexName-
The name of the index to create. Note that it is possible to create an index with an empty name.
keyPath-
The key path for the index to use. Note that it is possible to create an index with an empty
keyPath, and also to pass in a sequence (array) as akeyPath. optionsOptional-
An object which can include the following properties:
unique-
If
true, the index will not allow duplicate values for a single key. Defaults tofalse. multiEntry-
If
true, the index will add an entry in the index for each array element when thekeyPathresolves to an array. Iffalse, it will add one single entry containing the array. Defaults tofalse. locale