Skip to content

titleCaseKeys

Recursively transforms every key of a plain object (including keys nested inside arrays and nested objects) to Title Case. Handles camelCase, snake_case, kebab-case, and space-separated keys. Non-plain-object values — Date, Map, Set, class instances, primitives — are left untouched, only their position is walked into. An entry whose transformed key is a prototype-polluting string (__proto__, constructor, prototype) is silently skipped, same as the rest of @helpers4/object.

Note: unlike the other *CaseKeys variants, titleCase joins words with spaces (e.g. 'User Name') — those keys are only usable via bracket access (obj['User Name']), not dot notation. Useful for display-facing structures (form labels, table headers), not wire formats.

Available since v3.0.3

import { titleCaseKeys } from '@helpers4/object';
// or, from the all-in-one package (same code, one install):
import { titleCaseKeys } from 'helpers4/object';
titleCaseKeys<T>(value: T): T
ParameterTypeDescription
valueTThe object (or array of objects) to transform

T — A new value with every plain-object key converted to Title Case

Convert object keys into display-friendly labels

Section titled “Convert object keys into display-friendly labels”

Recursively converts every key to Title Case — useful for form labels or table headers.

titleCaseKeys({ user_name: 'Alice', home_address: { zip_code: '12345' } })
// => { 'User Name': 'Alice', 'Home Address': { 'Zip Code': '12345' } }

View source on GitHub