Skip to main content


TS JS Deno

Converts a string to camelcase.

Break the string into words and combine them capitalizing the first letter of each word, using a regexp.

const toCamelCase = (str: string) => {
let s = str
?.map((x: string) => x.slice(0, 1).toUpperCase() + x.slice(1).toLowerCase())
return s && s.slice(0, 1).toLowerCase() + s.slice(1);
toCamelCase("some_database_field_name"); // 'someDatabaseFieldName'
toCamelCase("Some label that needs to be camelized"); // 'someLabelThatNeedsToBeCamelized'
toCamelCase("some-javascript-property"); // 'someJavascriptProperty'
toCamelCase("some-mixed_string with spaces_underscores-and-hyphens"); // 'someMixedStringWithSpacesUnderscoresAndHyphens'