Search⌘ K
AI Features

Create an Index for the Object Store

Explore how to create an index in an IndexedDB object store using the createIndex method within the onupgradeneeded event. This lesson guides you through setting up index names, key paths, and options to efficiently organize and retrieve object store data in your web applications.

The createIndex() method

To create an index in IndexedDB, we use the createIndex() method of the IDBObjectStore interface. The createIndex() method can be called only inside the onupgradeneeded event handler.

Syntax

createIndex(name, keyPath)
createIndex(name, keyPath, options)
Syntax for the createIndex() method

The createIndex() ...