---
title: "What is an object store in IndexedDB?"  
description: "What is an object store in IndexedDB?"  
author: "ICSM Computer"  
published: 2025-07-01  
updated: 2025-07-01  
canonical: https://www.mindstick.com/interview/34301/what-is-an-object-store-in-indexeddb  
category: "database"  
tags: ["indexeddb"]  
reading_time: 3 minutes  

---

# What is an object store in IndexedDB?

In **IndexedDB**, an **object store** is like a **table** in a relational database. It’s where the actual **data records (objects)** are stored.

## What is an Object Store?

An **object store**:

- Holds **JavaScript objects** (not strings like `localStorage`).
- Has a **key** for each record, used to identify and retrieve data.
- Can have **indexes** for fast searching/filtering on object properties.

## Example

### Structure

Suppose you have this object:

```javascript
{ id: 1, name: "Alice", age: 25 }
```

You can store it in an object store named `"users"` with `"id"` as the key.

### Creating an Object Store (in `onupgradeneeded`)

```javascript
const request = indexedDB.open('MyDB', 1);

request.onupgradeneeded = (event) => {
    const db = event.target.result;

    // Create an object store named "users" with keyPath "id"
    const store = db.createObjectStore('users', { keyPath: 'id' });

    // Optionally create an index on 'name'
    store.createIndex('nameIndex', 'name', { unique: false });
};
```

### Inserting into the Object Store

```javascript
const tx = db.transaction('users', 'readwrite');
const store = tx.objectStore('users');

store.add({ id: 1, name: "Alice", age: 25 });
```

## Key Characteristics

| Feature | Description |
| --- | --- |
| **KeyPath** | A property (e.g. `'id'`) used as a unique key for each record |
| **Auto-increment** | Can auto-generate numeric keys if desired |
| **Indexable** | Can create indexes on any field for fast lookups |
| **Stores objects** | Holds whole JS objects, not just strings |
| **Multiple stores** | A single database can have multiple object stores (like tables) |

## Summary

- An **object store** is where data lives inside an IndexedDB database.
- It’s similar to a **table**, but stores **objects** with unique keys.
- You can create **indexes** to speed up lookups by object properties.

## Answers

### Answer by ICSM Computer

In **IndexedDB**, an **object store** is like a **table** in a relational database. It’s where the actual **data records (objects)** are stored.

## What is an Object Store?

An **object store**:

- Holds **JavaScript objects** (not strings like `localStorage`).
- Has a **key** for each record, used to identify and retrieve data.
- Can have **indexes** for fast searching/filtering on object properties.

## Example

### Structure

Suppose you have this object:

```javascript
{ id: 1, name: "Alice", age: 25 }
```

You can store it in an object store named `"users"` with `"id"` as the key.

### Creating an Object Store (in `onupgradeneeded`)

```javascript
const request = indexedDB.open('MyDB', 1);

request.onupgradeneeded = (event) => {
    const db = event.target.result;

    // Create an object store named "users" with keyPath "id"
    const store = db.createObjectStore('users', { keyPath: 'id' });

    // Optionally create an index on 'name'
    store.createIndex('nameIndex', 'name', { unique: false });
};
```

### Inserting into the Object Store

```javascript
const tx = db.transaction('users', 'readwrite');
const store = tx.objectStore('users');

store.add({ id: 1, name: "Alice", age: 25 });
```

## Key Characteristics

| Feature | Description |
| --- | --- |
| **KeyPath** | A property (e.g. `'id'`) used as a unique key for each record |
| **Auto-increment** | Can auto-generate numeric keys if desired |
| **Indexable** | Can create indexes on any field for fast lookups |
| **Stores objects** | Holds whole JS objects, not just strings |
| **Multiple stores** | A single database can have multiple object stores (like tables) |

## Summary

- An **object store** is where data lives inside an IndexedDB database.
- It’s similar to a **table**, but stores **objects** with unique keys.
- You can create **indexes** to speed up lookups by object properties.


---

Original Source: https://www.mindstick.com/interview/34301/what-is-an-object-store-in-indexeddb

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
