This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

createIndex

Summary

This method creates and returns a new index with the given name and parameters in the connected database.

Method of apis/indexeddb/IDBObjectStoreapis/indexeddb/IDBObjectStore

Syntax

var index = objectStore.createIndex(name, keyPath, optionalParameters);

Parameters

name

Data-type
String

Name of the index.

keyPath

Data-type
String

Name of the field to be indexed.

optionalParameters

Data-type
String

(Optional)

The options object whose attributes are optional parameters to this function. ‘unique’ specifies whether the index’s unique flag is set. ‘multiEntry’ specifies whether the index’s multiEntry flag is set.

Return Value

Returns an object of type DOM NodeDOM Node

IDBIndex

An object representing the new index.

Examples

// The transaction is already created

var objectStore = transaction.objectStore("ObjectStore_BookList");
var index = objectStore.createIndex("priceIndex", "price", {
    "unique": false,
    "multiEntry": true
});

View live example

Notes

The method throws an exception if

  • This method was not called from a “versionchange” transaction callback. Also occurs if a request is made on a source object that has been deleted or removed.
  • An index with the same name, compared in a case-sensitive manner, already exists in the connected database.

Related specifications

W3C IndexedDB Specification
W3C Proposed Recommendation

Attributions