Languages
[Edit]
EN

JavaScript - convert camelCase to Sentence Case

3 points
Created by:
Sujay
272

This article will show you how to convert camelCase to Sentence Case in JavaScript.

camelCase to sentence case conversion concept example:

mySampleText  ->  My Sample Text

 

Practical example

In the example below, we have created a function toSentenceCase() that converts text from the camelCase convention to the sentence case convention. If the function gets no value, it returns an empty string.

// ONLINE-RUNNER:browser;

const toSentenceCase = camelCase => {
   if (camelCase) {
       const result = camelCase.replace(/([A-Z])/g, ' $1');
       return result[0].toUpperCase() + result.substring(1).toLowerCase();
   }
   return '';
};

// Usage example:

console.log( toSentenceCase("mySampleText") ); // My sample text
console.log( toSentenceCase("anotherText")  ); // Another text

JavaScript - String (popular problems)

JavaScript - convert camelCase to sentence case
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join