What is a keyPath and how is it used in IndexedDB?
Ask by ICSM Computer
Updated 01 Jul 2025
In IndexedDB, a
keyPathis a property (or path) within your stored object that serves as its primary key — a unique identifier for each record.What is
keyPath?How
keyPathis UsedExample: Simple KeyPath
Now, when you store an object like this:
IndexedDB uses
101(fromid) as the primary key.Example: Nested KeyPath
Here, the object:
Will be stored with
999as the key.Example: Compound KeyPath
Now the combination of
firstNameandlastNameis the unique key.Without
keyPath(Manual Keys)If you don’t use a
keyPath, you must pass the key manually:Summary
keyPathadd()orput()