top of page
Writer's pictureThe Tech Platform

Program to Convert String from Snake_Case to CamelCase in JavaScript

Updated: Dec 16, 2021

Snake_Case: A string in snake_case uses the underscore character to separate each word. Each word in a snake_case string usually begins with a lowercase letter, although variants exist.


CamelCase: A camelCase string begins with a lowercase letter, each following word beginning with an uppercase letter. There are no intervening spaces or punctuation in a camelCase string.


Code:

let snakeCaseString = "The_Tech_Platform"  
const snakeToCamelCase = sentence => sentence  
    .split('_')  
    .map((word, index) => {  
        if (word === 0) {  
            return part.toLowerCase();  
        }  
        return firstUppercase(word);  
    })  
    .join('');  
const firstUppercase = word => word &&  
    word.charAt(0).toUpperCase() + word.slice(1);  
  
console.log(snakeCaseString);  
console.log(snakeToCamelCase(snakeCaseString));  

Output:




Read More:



The Tech Platform

0 comments

Comments


bottom of page