Languages
[Edit]
EN

JavaScript - first letter of each word uppercase

0 points
Created by:
ArcadeParade
666

In this article, we would like to show you how to make the first letter of each word uppercase in JavaScript.

Quick solution:

 

Practical example

Edit

In this example, we make the first letter of each word uppercase using:

  1. split() method split the text into an array of separate words,
  2. charAt() method with toUpperCase() to uppercase the first letter of each word,
  3. slice() method to get the rest of the word - without the first letter, so we can add it to the uppercase letter.
  4. join() method to convert the array back to the string.

Output:

Modern syntax - reusable arrow function

Edit

In this section, we present a solution that is equal to the above one but written in modern syntax.

Output:

References

Edit
  1. String.prototype.split() - JavaScript | MDN
  2. String.prototype.charAt() - JavaScript | MDN
  3. String.prototype.toUpperCase() - JavaScript | MDN
  4. String.prototype.slice() - JavaScript | MDN
  5. Array.prototype.join() - JavaScript | MDN
1
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.
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