For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/object/toKebabCaseKeys.md.

toKebabCaseKeys es-toolkit

Returns a new object with all keys in objects and arrays converted to kebab-case.

Kebab case is a naming convention where each word is written in lowercase and connected with dashes (-). For example, it's written as kebab-case.

const kebabCased = toKebabCaseKeys(obj);

Usage

toKebabCaseKeys(obj)

Use toKebabCaseKeys when you want to convert all keys of an object to kebab-case. Nested objects and objects within arrays are also converted recursively.

For example, object keys are converted as follows:

  • camelCasekebab-case (e.g. userIduser-id)
  • PascalCasekebab-case (e.g. UserIduser-id)
  • UPPERCASE_KEYSkebab-case (e.g. FIRST_NAMEfirst-name, LASTlast)
import { toKebabCaseKeys } from 'es-toolkit/object';

// Basic object conversion
const obj = { userId: 1, firstName: 'John', lastName: 'Doe' };
const result = toKebabCaseKeys(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 = toKebabCaseKeys(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: '[email protected]',
      phoneNumber: '123-456-7890',
    },
  },
};
const nestedResult = toKebabCaseKeys(nested);
// nestedResult is {
//   'user-data': {
//     'user-id': 1,
//     'contact-info': {
//       'email-address': '[email protected]',
//       'phone-number': '123-456-7890'
//     }
//   }
// }

Parameters

objTrequired

The object, array, or primitive value to convert keys to kebab-case.

Returns

Returns a new object with all keys converted to kebab-case.

ToKebabCaseKeys<T>
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.