Languages
[Edit]
EN

JavaScript - convert camelCase to Sentence Case

3 points
Created by:
Sujay
512

In this article, we would like to 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

Alternative titles

  1. JavaScript - convert camelCase to Sentence Case
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - 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