JavaScript example

Convert snake_case to camelCase in JavaScript

For predictable snake_case input, split on underscores, normalize each token, keep the first token lowercase, and capitalize later tokens. The helper also tolerates repeated, leading, and trailing underscores.

By Camel Case Converter Editorial TeamPublished Sep 12, 2026Last reviewed

JavaScript code

function snakeToCamel(value) {
  const parts = value.trim().replace(/^_+|_+$/g, "").split(/_+/).filter(Boolean)
  if (parts.length === 0) return ""
  return parts[0].toLowerCase() + parts.slice(1).map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()).join("")
}

snakeToCamel("user_profile_image")
// "userProfileImage"

Trim whitespace, remove leading or trailing underscores, and split on one or more underscores so repeated separators do not create empty middle tokens.

This is appropriate for genuine snake_case. If input can contain PascalCase, acronyms, spaces, dashes, or mixed separators, use a broader tokenizer.

Edge cases to consider

  • Acronyms such as API and URL may require project-specific casing.
  • Mixed input such as user_profile-URL needs broader tokenization.
  • Recursively converting object keys is different from converting one string.
  • Generated variable names may need reserved-word and identifier validation.

Example

BeforeAfter
user_profile_imageuserProfileImage
__user__profile__userProfile
api_response_urlapiResponseUrl
created_atcreatedAt

JavaScript code

const cases = [
  ["user_profile_image", "userProfileImage"],
  ["__user__profile__", "userProfile"],
  ["api_response_url", "apiResponseUrl"],
  ["created_at", "createdAt"],
]

for (const [input, expected] of cases) {
  console.assert(snakeToCamel(input) === expected, input)
}

Try the conversion online

Use the browser-based converter for quick checks, batch values, acronym handling, or inputs that mix several naming conventions.

Detected: snake_case
camelCase output
userProfileImageUrl

All naming formats

camelCase
userProfileImageUrl
PascalCase
UserProfileImageUrl
snake_case
user_profile_image_url
kebab-case
user-profile-image-url
CONSTANT_CASE
USER_PROFILE_IMAGE_URL
dot.case
user.profile.image.url
path/case
user/profile/image/url

Conversion happens locally in your browser. Your input is not sent to a conversion server.