Lodash _.camelCase() Method

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 6 Examples + 3 Try It
String utilities

What You’ll Learn

By the end of this tutorial, you’ll convert messy string labels into clean camelCase identifiers using Lodash’s _.camelCase() method.

01

Core Syntax

Call _.camelCase(string) with any phrase or identifier.

02

Separator Handling

Spaces, hyphens, underscores, and mixed separators become word boundaries.

03

API Normalization

Map snake_case JSON keys to camelCase for frontend code.

04

Case Helpers

Know when to use _.kebabCase, _.snakeCase, or _.startCase instead.

05

Tree-Shaking

Import lodash/camelCase for a tiny bundle footprint.

06

Production Tips

Avoid double-converting already-camelCase strings and watch acronym edge cases.

What Is _.camelCase()?

_.camelCase() converts a string into camelCase—the JavaScript convention where the first word is lowercase and each following word starts with an uppercase letter. Lodash strips non-word separators, splits the string into words, lowercases them, then joins without spaces.

💡
Beginner tip

Think of _.camelCase('foo-bar_baz') as “turn this label into a valid JavaScript property name.”

You will see this everywhere: mapping database column names to object keys, generating variable names from user labels, and cleaning up config keys from third-party APIs.

📝 Syntax

Pass any string (or omit it for an empty default):

javascript
_.camelCase([string=''])

Syntax Rules

  • string — the input to convert. Defaults to '' when omitted.
  • Separators — spaces, hyphens, underscores, and most punctuation act as word breaks.
  • Return value — a new camelCase string; the original is not modified.
  • Numbers — digits can appear inside words (e.g. version2Name).
  • Acronyms — consecutive capitals may be split differently than you expect; test edge cases.
javascript
import camelCase from "lodash/camelCase";

const kebab = "hello-world";
const result = camelCase(kebab);
// -> "helloWorld"

⚡ Quick Reference

TaskCode patternResult
Kebab to camel_.camelCase('foo-bar')fooBar
Snake to camel_.camelCase('foo_bar')fooBar
Spaces to camel_.camelCase('Foo Bar')fooBar
Mixed separators_.camelCase('foo-bar_baz')fooBarBaz
Reverse direction_.kebabCase('fooBar')foo-bar
Title-style words_.startCase('fooBar')Foo Bar
Mutates?
No

Returns a new string

Input
string

Any phrase or identifier

Opposite
_.kebabCase()

Hyphenated lowercase

Related
_.snakeCase()

Underscore lowercase

🧰 Parameters

Every argument to _.camelCase() and what it controls:

string Optional

The string to convert. When omitted or empty, returns an empty string.

_.camelCase('hello-world')
return value New string

A camelCase string built from the input words. The original string is unchanged.

// -> 'helloWorld'
separators Implicit

Spaces, hyphens, underscores, and most non-alphanumeric characters separate words before casing.

_.camelCase('foo_bar-baz')
edge cases Important

Already-camelCase inputs may still be re-processed. Test acronyms like XMLHttp if they matter.

_.camelCase('XMLHttpRequest')

For display titles with capitalized words, use _.startCase() instead of camelCase.

Examples Gallery

Practical _.camelCase() patterns with copy-ready code, sample output, and interactive Try It Yourself labs.

📚 Getting Started

Convert common separator styles into camelCase.

Example 1 — Kebab-case to camelCase

Turn a hyphenated label into a JavaScript-friendly property name.

javascript
import camelCase from "lodash/camelCase";

const kebabCaseString = "hello-world";
const camelCaseString = camelCase(kebabCaseString);

console.log(camelCaseString);
// -> "helloWorld"
Try It Yourself

How It Works

Lodash splits on the hyphen, lowercases hello, capitalizes world, and joins them.

Example 2 — Mixed separators and underscores

Handle snake_case and hyphen mixes in one call.

javascript
import camelCase from "lodash/camelCase";

const raw = "my_variable-name";
const result = camelCase(raw);

console.log(result);
// -> "myVariableName"
Try It Yourself

How It Works

Both underscore and hyphen are treated as word boundaries, producing a single camelCase identifier.

Example 3 — Normalize API response keys

Convert snake_case keys from a REST payload into camelCase for your frontend models.

javascript
import camelCase from "lodash/camelCase";

const apiResponse = {
  user_name: "Ada",
  account_id: 7
};

const normalized = {};
for (const key of Object.keys(apiResponse)) {
  normalized[camelCase(key)] = apiResponse[key];
}

console.log(normalized);
// -> { userName: "Ada", accountId: 7 }
Try It Yourself

How It Works

Loop object keys and run each through camelCase before assigning to the new object.

Example 4 — Space-separated phrases

Convert human-readable labels from forms or CSV headers.

javascript
import camelCase from "lodash/camelCase";

const label = "First Name";
const fieldName = camelCase(label);
// -> "firstName"

How It Works

Spaces split the phrase into words; Lodash lowercases each word and capitalizes every word after the first, which is how form labels become safe object keys.

Example 5 — Map over an array of labels

Batch-convert a list of column headers in one line.

javascript
import camelCase from "lodash/camelCase";

const headers = ["order-id", "ship_date", "Customer Name"];
const keys = headers.map(camelCase);
// -> ["orderId", "shipDate", "customerName"]

How It Works

Pass camelCase directly to Array.prototype.map—each header is converted independently, which is handy when parsing CSV or spreadsheet columns.

🚀 Beyond the Basics

Related case helpers and when to pick a different tool.

🧠 How _.camelCase() Works

1

Receive input string

Lodash reads the string argument (default empty).

Input
2

Split into words

Non-alphanumeric characters and case changes define word boundaries.

Parse
3

Normalize each word

Words are lowercased; the first character of each subsequent word is uppercased.

Transform
4

Join without separators

Words are concatenated into a single camelCase string.

Join
=

camelCase string returned

A new string ready for object keys, variables, or config properties.

📝 Notes

  • _.camelCase() returns a new string—the original is untouched.
  • It is ideal for identifiers, not for sentence capitalization (use _.capitalize()).
  • Acronyms and consecutive capitals may produce surprising splits—always test your real data.
  • Already camelCase strings may still be re-processed; guard with a check if idempotency matters.
  • Pair with object mapping when normalizing API payloads with snake_case keys.
  • Import only lodash/camelCase to keep bundles small.

Conclusion

_.camelCase() is the go-to Lodash helper when you need consistent JavaScript-style identifiers from messy human-readable labels. Use it on API keys, form labels, and config names.

When you need hyphens for URLs or underscores for databases, reach for _.kebabCase() or _.snakeCase() instead.

💡 Best Practices

✅ Do

  • Use for JS property names and variable identifiers
  • Import lodash/camelCase for tree-shaking
  • Test acronym-heavy strings from legacy systems
  • Batch-convert with .map(camelCase) on header arrays
  • Pair with object key remapping for API normalization

❌ Don’t

  • Use for display titles meant for humans (prefer _.startCase)
  • Assume idempotency on already-camelCase strings
  • Rely on it for locale-sensitive proper nouns
  • Confuse camelCase with _.capitalize (only first letter)
  • Forget to validate output when security depends on exact key names

Key Takeaways

Knowledge Unlocked

Five things to remember about _.camelCase()

Use these points whenever you need camelCase identifiers from arbitrary strings.

5
Core concepts
🔀 02

Separators

Hyphens, spaces, underscores split words.

Parse
📦 03

API keys

Normalize snake_case payloads.

Pattern
04

Tree-shake

Import lodash/camelCase only.

Bundle
🔄 05

Case family

Compare kebabCase and snakeCase.

Next step

❓ Frequently Asked Questions

_.camelCase() converts a string to camelCase by splitting it into words, lowercasing them, capitalizing subsequent words, and joining without separators.
No. Strings are immutable in JavaScript. _.camelCase() always returns a new string.
_.capitalize() only uppercases the first character of the entire string. _.camelCase() restructures the whole string into JavaScript identifier form.
Yes. Map each key through _.camelCase() when transforming API responses for frontend models.
Spaces, hyphens, underscores, and most non-alphanumeric characters act as word boundaries.
For production bundles, prefer import camelCase from 'lodash/camelCase' to include only this function.
Did you know?

_.camelCase() shares the same word-splitting rules as _.kebabCase() and _.snakeCase()—only the join style differs. For human-readable titles (not JS identifiers), use _.startCase() instead.

Practice _.camelCase() in the Live Editor

Open the Try It editor, run the examples, and experiment with your own strings.

Open Try It editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful