← Back to all snippets
JAVASCRIPT

Convert Kebab-case to CamelCase

Transform kebab-case strings (e.g., 'font-size') into camelCase (e.g., 'fontSize') using JavaScript regex, essential for dynamic CSS property handling or object key conversions.

function kebabToCamelCase(kebabString) {
  return kebabString.replace(/-([a-z])/g, (match, letter) => letter.toUpperCase());
}

// Example usage:
const kebab = 'background-color-value';
const camel = kebabToCamelCase(kebab);
console.log(camel); // Output: "backgroundColorValue"
How it works: This regex `/-([a-z])/g` finds hyphens followed by a lowercase letter. The `([a-z])` part captures the letter. The replace function then takes this captured letter and converts it to uppercase, effectively removing the hyphen and capitalizing the subsequent letter, transforming the string from kebab-case to camelCase.

Need help integrating this into your project?

Our team of expert developers can help you build your custom application from scratch.

Hire DigitalCodeLabs