- Instant help with your JavaScript coding problems

Convert snake case to camel case in JavaScript

Question:
How to convert snake case to camel case in JavaScript?
Answer:
function snakeToCamel(str){
    return str.replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase());
}

console.log(snakeToCamel('simple_snake_case_text')); // simpleSnakeCaseText
Description:

Converting a snake case text like simple_snake_case to a camel case text like simpleCamelCase can be done by using the built-in replace method extended with some regular expression.

Share "How to convert snake case to camel case in JavaScript?"
Related snippets:
Tags:
snake to camel, snake case, camel case, convert, javascript
Technical term:
Convert snake case to camel case in JavaScript