> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# toConstantCaseKeys es-toolkit

Returns a new object with all keys in objects and arrays converted to CONSTANT\_CASE.

Constant case is a naming convention where each word in an identifier is written in uppercase and connected with underscores (`_`). For example, it's written as `CONSTANT_CASE`.

```typescript
const constantCased = toConstantCaseKeys(obj);
```

## Usage

### `toConstantCaseKeys(obj)`

Use `toConstantCaseKeys` when you want to convert all keys of an object to CONSTANT\_CASE. Nested objects and objects within arrays are also converted recursively.

For example, object keys are converted as follows:

- `camelCase` → `CONSTANT_CASE` (e.g. `userId` → `USER_ID`)
- `PascalCase` → `CONSTANT_CASE` (e.g. `UserId` → `USER_ID`)
- `snake_case` → `CONSTANT_CASE` (e.g. `first_name` → `FIRST_NAME`, `last` → `LAST`)

```typescript
import { toConstantCaseKeys } from 'es-toolkit/object';

// Basic object conversion
const obj = { userId: 1, firstName: 'John', lastName: 'Doe' };
const result = toConstantCaseKeys(obj);
// result is { USER_ID: 1, FIRST_NAME: 'John', LAST_NAME: 'Doe' }

// Objects within arrays are also converted
const users = [
  { userId: 1, firstName: 'John' },
  { userId: 2, firstName: 'Jane' },
];
const convertedUsers = toConstantCaseKeys(users);
// convertedUsers is [{ USER_ID: 1, FIRST_NAME: 'John' }, { USER_ID: 2, FIRST_NAME: 'Jane' }]

// Nested objects are fully converted
const nested = {
  userData: {
    userId: 1,
    contactInfo: {
      emailAddress: 'john@example.com',
      phoneNumber: '123-456-7890',
    },
  },
};
const nestedResult = toConstantCaseKeys(nested);
// nestedResult is {
//   USER_DATA: {
//     USER_ID: 1,
//     CONTACT_INFO: {
//       EMAIL_ADDRESS: 'john@example.com',
//       PHONE_NUMBER: '123-456-7890'
//     }
//   }
// }
```

#### Parameters


objTrequired

The object, array, or primitive value to convert keys to CONSTANT\_CASE.

#### Returns

Returns a new object with all keys converted to CONSTANT\_CASE.

```typescript
ToConstantCaseKeys<T>
```


Source: es-toolkit

Re-exported verbatim from [`es-toolkit`](https://es-toolkit.dev/reference/object/toConstantCaseKeys.html). Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.
