In this article we will learn how to capitalize a string in JavaScript.
It is very common to capitalize a string in JavaScript in JavaScript.
Problem
Now we have a problem which is that we want to capitalize a string.
Now let's imagine that we have an string like this:
"hello world!"
And want to capitalize this string to became like this:
"HELLO WORLD!"
How to solve this problem?
The solution to this problem is easy, especially since there is a built-in function that does this called toUpperCase()
.
Capitalize a string using toUpperCase
As we said before, we can use toUpperCase
method to capitalize our string.
Let's see an example:
// String
const string = "hello world!";
// Capitalize your string
const capitalize = string.toUpperCase();
// Result:
console.log(capitalize);
Output
HELLO WORLD!
Thank you for reading
Thank you for reading my blog. 🚀