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.
Fundamentals
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.
Foundation
📝 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"
Cheat Sheet
⚡ Quick Reference
Task
Code pattern
Result
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
Reference
🧰 Parameters
Every argument to _.camelCase() and what it controls:
stringOptional
The string to convert. When omitted or empty, returns an empty string.
_.camelCase('hello-world')
return valueNew string
A camelCase string built from the input words. The original string is unchanged.
// -> 'helloWorld'
separatorsImplicit
Spaces, hyphens, underscores, and most non-alphanumeric characters separate words before casing.
_.camelCase('foo_bar-baz')
edge casesImportant
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.
Hands-On
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.
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.
All three share Lodash word-splitting rules but format output differently for URLs, constants, or JS identifiers.
Compare
📋 _.camelCase vs related operations
Topic
_.camelCase
_.kebabCase
_.snakeCase
_.startCase
Output style
fooBar
foo-bar
foo_bar
Foo Bar
Typical use
JS identifiers
URLs, CSS
DB columns
Titles, labels
First word
lowercase
lowercase
lowercase
Capitalized
Separator
none
hyphen
underscore
space
Mutates input
No
No
No
No
🧠 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.
Important
📝 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.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about _.camelCase()
Use these points whenever you need camelCase identifiers from arbitrary strings.
5
Core concepts
📝01
Identifiers
Best for JS keys and variables.
Basics
🔀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.