> For the complete documentation index, see [llms.txt](https://gitbook.roboqo.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.roboqo.com/global-objects/storage-object.md).

# Storage Object

## Storage Object Documentation

### Description

The `Storage` object provides an in-memory key-value storage system that synchronizes with a remote service using the `Roboqo` RPC interface. It supports both local and session storage types and provides methods to manipulate stored data efficiently. You can access storage via **localStorage** and **sessionStorage** global objects.

### Methods

#### `setItem`

**Description**

Stores a value associated with a key and synchronizes it with the remote storage.

**Signature**

```typescript
setItem(key: string, value: any): void
```

**Parameters**

* `key` (`string`): The key under which the value is stored.
* `value` (`any`): The value to store.

**Example Usage**

```typescript
localStorage.setItem("username", "JohnDoe");
```

***

#### `getItem`

**Description**

Retrieves a stored value by its key.

**Signature**

```typescript
getItem(key: string): any
```

**Parameters**

* `key` (`string`): The key to retrieve the stored value.

**Returns**

* `T | null`: The stored value or `null` if the key does not exist.

**Example Usage**

```typescript
const username = localStorage.getItem("username");
console.log(username); // Output: "JohnDoe"
```

***

#### `removeItem`

**Description**

Removes a value from storage and synchronizes the removal with the remote storage.

**Signature**

```typescript
removeItem(key: string): void
```

**Parameters**

* `key` (`string`): The key to remove.

**Example Usage**

```typescript
localStorage.removeItem("username");
```

***

#### `clear`

**Description**

Clears all stored data and synchronizes the removal with the remote storage.

**Signature**

```typescript
clear(): void
```

**Example Usage**

```typescript
storage.clear();
```

***

#### `keys`

**Description**

Retrieves an array of all stored keys.

**Signature**

```typescript
keys(): string[]
```

**Returns**

* `string[]`: An array of stored keys.

**Example Usage**

```typescript
const storedKeys = localStorage.keys();
console.log(storedKeys);
```

***

#### `toJSON`

**Description**

Converts the stored data into a JSON object.

**Signature**

```typescript
toJSON(): Record<string, any>
```

**Returns**

* `Record<string, any>`: An object representation of the stored data.

**Example Usage**

```typescript
const jsonData = localStorage.toJSON();
console.log(jsonData);
```

***

### Example Usage

```typescript
localStorage.setItem("username", "Alice");
console.log(localStorage.getItem("username")); // Output: "Alice"
localStorage.removeItem("username");
localStorage.clear();
```
